1
You will need this instead:
{% for article in article_list %}
{{ article.title }}
{% for t in article.joining.all %}
{{ t.list }}
{% endfor %}
{% endfor %}
Since you are iterating through the “other” side of the relationship (i.e. articles), you will access each article’s related List
via the article’s list_set (to which you have given the related name ‘joining’).
Incidentally, you might want to find a different name for your List
model. It makes this discussion somewhat confusing.
1
You can not access child.field this way. If your parent child are properly referenced, you have to do like:
{% for parent in parent_list %}
my parent value: {{parent.field1}}
{%for child in parent.child_set.all %}
My child value {{child.field2}}
{%endfor%}
{%endfor%}
Thanks
- [Answered ]-Django rest framework serializer with extra field
- [Answered ]-Accessing a List out of order in Jinja
- [Answered ]-2 OneToOneField defined for two tables. One got deleted but not other
Source:stackexchange.com