Answer the question
In order to leave comments, you need to log in
Why takes ManyToManyField on save?
Hello everyone , the
problem is that when
from django.db import models
from apps.product.models import Product
from apps.core.models import Category
class CategoryConverter(models.Model):
product = models.ManyToManyField(Product, blank=True, null =True)
category = models.ForeignKey(Category, blank=True, null=True)
def save(self, *args, **kwargs):
print(self.category)
print(self.product)
if self.product and self .category:
for product in self.product.all():
product.category.add(self.category)
product.save()
return super(CategoryConverter, self).save(*args, **kwargs)
I select products in the admin but when saving self.product is empty Thank you in
advance )
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question