I am looping through cart-items, and want to multiply quantity with unit-price like this:
{% for cart_item in cart.cartitem_set.all %}
{{cart_item.quantity}}
Or you can set the property on the model:
class CartItem(models.Model):
cart = models.ForeignKey(Cart)
item = models.ForeignKey(Supplier)
quantity = models.IntegerField(default=0)
@property
def total_cost(self):
return self.quantity * self.item.retail_price
def __unicode__(self):
return self.item.product_name