I'm new in django, I would like to display my view.py to index.html,
the view.py:
def index(request):
context_dict = {}
customers = Customer.objects.all()
carts = Cart.objects.select_related('customer')
goods = Good.objects.select_related('cart__customer')
context_dict['Cart']=carts
context_dict['Good']=goods
context_dict['Customer'] = customers
return render(request, 'index.html', context=context_dict)
and the index.html for loop is like this:
<ul>
{% for customer in Customer %}
<li>{{ customer.name }}</li>
{% for cart in Cart %}
{% if customer.id == cart.id %}
{% for good in Good %}
{% if cart.id == good.id %}
{{good.name}}--{{good.count}}--{{good.price}}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
</ul>
but the result displayed like this:
Bob should have water--2--50 under it. it seems customer.id == cart.id cannot match. but I don't know how to fix it. please help, thanks a lot!
