Reputation: 331
I was created def function in model.py file and now i want to get this function in view.py file. I know how to get this function in template file but i dont know how to get this function in view file for example: In model.py file:
class CartItem(models.Model):
# cart = models.ForeignKey("Cart")
cart = models.ForeignKey(
'Cart',
on_delete=models.CASCADE,
)
product = models.ForeignKey(product_models.Product,on_delete=models.CASCADE)
item = models.ForeignKey(product_models.ProductDetails,on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=1)
def __unicode__(self):
return self.item.title
@property
def item_week_real_total(self):
return self.item.get_week_price() * self.quantity
In view.py file
cart_item = CartItem.objects.filter(cart_id=request.session['cart_id'])
for cart_item_data in cart_item:
week_total = cart_item_data.item_week_real_total()
But i got error 'decimal.Decimal' object is not callable
Upvotes: 1
Views: 248
Reputation: 8314
item_week_real_total
should be called like a property/attribute, not a method. You decorated it with @property
so it should be called like:
cart_item_data.item_week_real_total
without the ()
Upvotes: 1