class Cart(models.Model):
user = models.ForeignKey(User,null=True, blank=True,on_delete=models.CASCADE)
products = models.ManyToManyField(Product, blank=True)
subtotal = models.DecimalField(default=0.00, max_digits=100, decimal_places=2)
total = models.DecimalField(default=0.00,max_digits=100,decimal_places=2)
quantity = models.IntegerField(default=0, null=True, blank=True)
updated = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)
objects = CartManager()
def __str__(self):
return str(self.id)
@property
def get_total_item(self):
total = self.products.price * self.quantity
return total
class Product(models.Model):
title = models.CharField(max_length=120)
slug = models.SlugField(blank=True)
description = models.TextField()
price = models.DecimalField(decimal_places=2, max_digits=20, default=39.99)
image = models.ImageField(upload_to=upload_image_path,null=True, blank=True)
featured = models.BooleanField(default=False)
active = models.BooleanField(default=True)
timestamp = models.DateTimeField(auto_now_add=True)
objects = ProductManager()
@property
def get_total_item(self):
total = self.products.price * self.quantity
return total
(error in products,price how to access it )
In this self.products.price I cannot accesss the price from products.
I'm trying to retrieve multiple prices of product and quandity of individiual products.
I am trying to get a single value from product model but I dont know how to access that in many to many realtionships.
