krzyhub
krzyhub

Reputation: 6540

Problem with django templates

Is there any solution to do something like this:

{% for c in categories %}
   {% for s in c.subcategory_set %}
   <li>{{ s.name }}</li>
   {% endfor %}
{% endfor %}

???

Upvotes: 0

Views: 48

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799580

Reverse relations on a FK have a manager. As such, you need to use the all() method if you want to access all related objects.

{% for s in c.subcategory_set.all %}

Upvotes: 3

Related Questions