考虑以下(简化的)Django模型:
class productFamily(models.Model):
name = models.CharField(max_length = 256)
text = models.TextField(blank = False)
image = models.ImageField(upload_to="products/img/")
def __unicode__(self):
return self.name
class productModel(models.Model):
productFamily = models.ForeignKey('productFamily')
productFamily.help_text = 'ProductFamily to which this model belongs.'
artNumber = models.CharField(max_length=100)
name = models.CharField(max_length = 256)
productDownloads = models.ManyToManyField('productModelDownLoad')
productDownloads.help_text = 'Files associated to this product Model.'
def __unicode__(self):
return self.name
class productModelDownload(models.Model):
file = models.FileField(upload_to="products/downloads/")
def __unicode__(self):
return str(self.file)
我收到以下错误:
products.productmodel: 'productDownloads' has an m2m relation with model productModelDownLoad, which has either not been installed or is abstract.
我在django文档中找到了一个页面似乎可以解决此问题,但是我不太理解它的含义:
http://www.djangoproject.com/documentation/models/invalid_models/
该模型对我来说看起来很有效,那么这里出了什么问题?
最佳答案
您必须将class productModelDownload放在productModel类之前。
在验证模型时,从上到下对其进行处理。
关于django - 尚未安装或抽象的多对多关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4575068/