17.1. Displaying total price
Having displayed the ordered products in the cart, the next step is to display the total price of all items.
@property
def total_price(self) :
return self.quantity * self.itemstock.product.price@property
def total_quantity(self) :
items_ordered = OrderedItem.objects.filter(order__id = self.id) #? gets all the items of the order
total_quantity = sum([item.quantity for item in items_ordered])
return total_quantity
@property
def total_cost(self) :
items_ordered = OrderedItem.objects.filter(order__id = self.id) #? gets all the items of the order
total_cost = sum([item.total_price for item in items_ordered])
return total_costLast updated