[Django]-Django select_related: How to display related table data in a template

7👍

I figured it out. I’m leaving this question and answer here for the next poor soul who has to nut his way through this conundrum.

{% for order in list_of_orders %}
<tr>
    <td>{{ order.order_id.cust_id.customer_name }}</td>
    <td>{{ order.order_id.invoice_number }}</td>
    <td>{{ order.order_id.invoice_creation_date }}</td>
    <td>{{ order.product_id.price }}</td>
</tr>
{% endfor %}
👤Ben

Leave a comment