I’d like to show my top level categories if the parent is equal to one. The topcats is a queryset that contains category items. However the code starred below is not working. It is not finding any cat items with parent = 1. Any idea why?
{% for cat in topcats %}
**{% if cat.parent == 1 %}**
<a href ="/x/{{cat.id}}/dir/"><h3>{{ cat.category }}</a></h3>
{% for each in topcats %}
{% if each.parent == cat.id %}
<h5>{{ each }}</h5>
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
Note: parent is a TreeForeignKey in the database
I’d say
cat.parentis a model object.This should work for you:
However, this is quite hackish, as the parent node’s id does not necessarily have a value of
1. The is_root_node() method is a better approach: