Models are-
class Product(models.Model):
name = models.CharField(max_length=50)
price = models.IntegerField(default=0)
seller=models.ForeignKey(Seller,null=True,on_delete=models.CASCADE,)
category = models.ForeignKey(Category,null=True, on_delete=models.CASCADE,)
description = models.CharField(max_length=200, default='' , null=True , blank=True)
image = models.ImageField(upload_to='uploads/products/')
rating=models.FloatField(null=True)
people=models.IntegerField(default=0,null=True)
customers=models.ManyToManyField(Customer,blank=True)
class Customer(models.Model):
user_name = models.CharField(max_length=50)
phone = models.IntegerField(default='8928')
email = models.EmailField()
password = models.CharField(max_length=500)
qq=Product.objects.get(id=8)
print(qq)
print(Customer.objects.all().first())
qq.customers.add(Customer.objects.all().first())
print("qq.customers is",qq.customers)
"""
Product object (8)
Customer object (1)
qq.customers is store.Customer.None"""
I want to know how we can add customers in product.customers which is showing none in this problem .Please help me to solve this
Aucun commentaire:
Enregistrer un commentaire