0👍
✅
You can use {% ifchanged %} template tag:
{% for post in posts %}
{% ifchanged %}<h3>{{ post.date }}</h3>{% endifchanged %}
<div>{{ post.name }}</div>
{% endfor %}
2👍
There is an inbuilt template tag for that – regroup
!
This isn’t perfect, but with the documentation it should get you close.
{% regroup posts by date as date_list %}
<ul>
{% for date in date_list %}
<li>{{ date.grouper }}
<ul>
{% for item in date.list %}
<li>{{ date.name }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
- [Answered ]-Seemingly quick filter field-lookup is slow
- [Answered ]-Django: Display attributes of Person model
- [Answered ]-Django rest project dockerfile
- [Answered ]-Django admin manytomany field
- [Answered ]-Redirection to index in Django and Angular
Source:stackexchange.com