[Answer]-Django model cross reference in templatre

1👍

A Card has numerous CardTypes (as it’s a ForeignKey relationship), not just one. You have:

<td>Type {{ card.cardtype__set.all.sName }} </td>

You need to loop through all the CardTypes related to the Card:

{% for card in cardLoc %}
...
    {% for cardtype in card.cardtype__set.all %}
        <td>Type {{ cardtype.sName }}</td>
    {% endfor %}
...
{% endfor %}

Leave a comment