django – 多对多关系,既没有安装也没有抽象

考虑以下(简化)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/

该模型看起来对我有用,那么这里的问题是什么?

最佳答案
您必须在productModel类之前放置类productModelDownload.
它们在验证模型的同时从上到下进行处理.

转载注明原文:django – 多对多关系,既没有安装也没有抽象 - 代码日志