python - Django grouping dictionary in a template -
i have view group list every session :
def group_list(): attendance = student.objects.values('session', 'group', 'full_name',).order_by('session','group') return attendance
the dictionary :
{'full_name': u'user1', 'session': 1, 'group': u'a'} {'full_name': u'user2', 'session': 1, 'group': u"b"} {'full_name': u'user3', 'session': 2, 'group': u"b"} {'full_name': u'user4', 'session': 99, 'group': u'a'} {'full_name': u'user5', 'session': 99, 'group': u"c"}
is there way make loop or nested loop template output ?
session 1 : group -user1 -... group b -user2 session 2 : group group b -user3
perhaps did view wrong , should generate different dictionary grouped session , groups ?
you can use regroup
tag.
for example, assuming pass attendance
template:
{% regroup attendance session session_list %} {% session in session_list %} session: {{ session.grouper }} {% regroup session.list group group_list %} {% group in group_list %} group: {{ group.grouper }} {% student in group.list %} - {{ student.full_name }} {% endfor %} {% endfor %} {% endfor %}
Comments
Post a Comment