【发布时间】:2011-03-02 15:58:58
【问题描述】:
我正在尝试在模板中以下表格式输出查询
RAW.objects.filter(at_date__year='2011',at_date__month='02').values('user','attend').order_by().annotate(total=Count('attend'))
查询的输出
[{'user': u'sushanth', 'total': 13, 'attend': u'P'}, {'user': u'sushanthreddy', 'total': 2, 'attend': u'A'}, {'user': u'ram', 'total': 5, 'attend': u'P'}, {'user': u'ram', 'total': 2, 'at_attend': u'PL'}]
在这里我想让用户在模板中与众不同,以不同的标题格式参加,并总计到相应的标题。
user P A PL
sushanth 13 2 0
ram 5 0 2
对此有什么帮助吗?
【问题讨论】:
-
尝试合并列表中的字典,使您拥有 [{'user': 'susthanth', 'P': 13, 'A': 2, 'PL': 0} .. ] .在模板中浏览列表会更容易,因为每行都有一个列表条目。
-
好主意,我会尝试更新你,如果可能的话如何合并以上 dict.sorry for troubling
标签: python django django-models django-templates django-views