[Answer]-Many to many relation. Display data in template

1👍

Just with the normal dot notation. toys is an instance of the Toy model so you can access the attributes on it:

{% for box in boxes %}
    {% for toy in box.toys.all %}
        Toy: {{ toy.name }}<br/>
        Price: {{ toy.price }}<br/>
    {% endfor %}
{% endfor %}

Note that I’ve changed your variable names, which were confusing: the box variable that you passed to the template should really be boxes, as it’s a set of all the boxes owned by that proprietor, while toys inside the template should be toy, as it’s one specific toy from a box, not a set.

Leave a comment