I'm following the latest Tango book and was experimenting with different ways of looping through categories and subcategories to create a list. I have a 'Category' and 'Page' model, where Page has a foreign key to Category's ID. To display a list with sub-bullets I simply passed all categories and pages to a template and then looped through Page:
<ul>
{% if cats %}
{% for c in cats %}
{% if c == act_cat %}
<strong><li><a href="{% url 'show_category' c.slug %}">{{
c.name }}</a></li>
</strong>
{% else %}
<li><a href="{% url 'show_category' c.slug %}">{{
c.name }}</a>
{% endif %}
{% for p in pages %}
{% if p.category_id == c.pk %} <ul><li><a href="{{ p.url }} ">{{ p.title }}</li></ul>
{% endif %}
{% endfor %}
{% endfor %}
{% else %}
<li><strong>There are no categories present.</strong></li>
{% endif %}
</ul>
Is this considered the best way to do such a thing?