Я пытаюсь добавить много ко многим файлам в django, но получаю ошибку

#python #django #mongodb #web

Вопрос:

Модели являются-

 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"""
 

Я хочу знать, как мы можем добавить клиентов в product.customers, которые не отображаются в этой проблеме .Пожалуйста, помогите мне решить эту проблему

Ответ №1:

 print(qq.customers.all())
 

Это покажет клиентам.