[Answered ]-ManyToMany field returns None instead of giving me the data

1👍

{% for order in order %} will not work correctly.

Change your view:

def customer_info(request,pk):
    customer = Customer.objects.get(id=pk)
    orders = customer.orders_set.all()
    
    context={
        'customer': customer,
        'orders': orders
    }
    return render(request,'customer_info.html',context)

And your template:

<table>
    <tr>
        <td>Name: {{customer.name}}</td>
        <td>
            Orders:
            {% for order in orders %}
                {{ order.items.all }}
            {% endfor %}
        </td>
    </tr>
</table>

Leave a comment