Возникает исключение (NOT NULL constraint failed: market_product.fk_market_id), кода добавляю товар в магазин через форму. Если в поле fk_market установить null=True, то ошибки нет, но и связь товара с магазином не устанавливается и нужно это делать через админку
class Market(models.Model):
category = models.ForeignKey(Category, on_delete=models.PROTECT)
slug = models.SlugField(max_length=20, unique=True, db_index=True)
name = models.CharField(max_length=30, unique=True, db_index=True)
published = models.DateTimeField(default=timezone.now)
seller = models.ForeignKey(Profile, on_delete=models.CASCADE)
def save(self, *args, **kwargs):
self.slug = slugify(self.name)
super(Market, self).save(*args, **kwargs)
def __str__(self):
return self.name
class Product(models.Model):
fk_market = models.ForeignKey(Market, on_delete=models.CASCADE)
name_product = models.CharField(max_length=40, db_index=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
image = models.ImageField(upload_to='products/%Y/%m/%d', null=True)
description = models.TextField(max_length=200, blank=True)
slug = models.SlugField(max_length=40, db_index=True)
created = models.DateTimeField(auto_now_add=True)
available = models.BooleanField(default=True)
def save(self, *args, **kwargs):
self.slug = slugify(self.name_product)
super(Product, self).save(*args, **kwargs)
def __str__(self):
return self.name_product