2👍
✅
I think you are looking for regroup
food = Food.objects.all()
{% regroup food by food_type as food_list %}
<ul>
{% for food_type in food_list %}
<li>{{ food_type.grouper }}
<ul>
{% for item in food_type.list %}
<li>{{ item }}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
Source:stackexchange.com