1👍
✅
Use regroup
tag:
<label>Food</label>
{% regroup foods by category as category_list %}
<ul>
{% for category in category_list %}
<li>
<label>{{ category.grouper }}</label>
<ul>
{% for food in category.list %}
<li>{{ food.name }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
Source:stackexchange.com