django - List per Date python -
i creating list page , have concept. data
list = [ {'exec_date': datetime.date(2015, 9, 30), 'name': 'aaa', 'status': 'pe'}, {'exec_date': datetime.date(2015, 10, 29), 'name': 'bbb', 'status': 'dn'}, {'exec_date': datetime.date(2015, 9, 30), 'name': 'ccc', 'status': 'pe'}, {'exec_date': datetime.date(2015, 9, 30), 'name': 'ddd', 'status': 'dn'}, {'exec_date': datetime.date(2015, 9, 7), 'name': 'eee', 'status': 'dn'}, {'exec_date': datetime.date(2015, 9, 30), 'name': 'fff', 'status': 'ny'}]
and display output this
2015-9-7 1. eee, dn 2015-9-30 1. aaa, pe 2. ccc, pe 3. ddd, dn 4. fff, ny 2015-10-29 1. bbb, dn
i thinking loop display dates once , not repeat it.
@gocht result. have noticed. sept. 30, 2015 repeats 3 times.
sept. 30, 2015 1.set task finished, pe oct. 29, 2015 1.new activity task, dn sept. 30, 2015 1.new activity user, pe 2.new activity user, dn sept. 7, 2015 1.new activity task, dn sept. 30, 2015 1.new activity user, ny
try this:
from django.db.models import f model.objects.values('date').distinct().annotate(name=f('name'), status=f('status'))
edit
one option show in template usgin regroup template tag, , forloop show index number:
{% regroup list exec_date list_data %} <ul> {% exec_date in list_data %} <li>{{ exec_date.grouper }} <ul> {% item in exec_date.list %} <li> {{ forloop.counter }}.{{ item.name }}, {{ item.status }}</li> {% endfor %} </ul> </li> {% endfor %} </ul>
Comments
Post a Comment