class Product(models.Model):
title = models.CharField(max_length=120)
shops = models.ManyToManyField('shop', blank=True)
default_shop = models.ForeignKey('shop', related_name='shop_products', null=True, blank=True)
categories = models.ManyToManyField('Category', blank=True)
default = models.ForeignKey('Category', related_name='default_category', null=True, blank=True)
def image_upload_to_shop(instance, filename):
name = instance.name
slug = slugify(name)
basename, file_extension = filename.split(".")
new_filename = "%s-%s.%s" %(slug, instance.id, file_extension)
return "products/%s/shop/%s" %(slug, new_filename)
class shop(models.Model):
name = models.CharField(max_length=120)
image = models.ImageField(upload_to=image_upload_to_shop, blank=True)
location = models.CharField(max_length=120)
def __unicode__(self):
return self.name
我有一个名为产品,商店和类别等的模型 如果我在单独的项目中有产品和商店模型,以上所有代码都工作正常..但是当我添加类别和其他东西时,它会在添加新商店时向我显示此错误
IntegrityError at /admin/products/shop/add/
products_shop.product_id may not be NULL