【发布时间】:2019-03-09 12:42:44
【问题描述】:
我从 Django 开始,我想知道如何从我的 Django 查询集中获取属性。
我有这个查询集:
get_country = Download.objects.filter(pub__publication__id=pubsd.id).values('country__name').order_by('country__name').annotate(count_country=Count('country__name'))
返回:
<QuerySet [{'country__name': 'France', 'count_country': 1}, {'country__name': 'Germany', 'count_country': 2}]>
所以我想在我的模板中显示count_country最高的国家/地区名称
我想知道我该怎么做?
非常感谢
【问题讨论】:
-
所以你只对
Country和Downloads最多的Country感兴趣? -
是的,从下载次数最多的国家/地区获取名称;)