Skip to content
Advertisement

Django items = order.orderitem_set.all() returning empty value for quantity

When I try and put the {{ item.product.quantity }} in it returns an empty value. The quantity value is filled in in the database. I can’t seem t pinpoint the problem. I have tried printing the quantity value but got the same results.

cart.html

JavaScript

views.py

JavaScript

models.py

JavaScript

If I do print(items) the result would be:

JavaScript

Advertisement

Answer

So quantity is a field of the Model OrderItem.

Your query for your returned items object is:

JavaScript

with Order being:

JavaScript

and quantity in

JavaScript

So your returned object doesn’t contain

JavaScript

So you gotta use (Thanks for highlighting it @Jakumi)

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement