Ema*_* Ey 6 django django-models
考虑以下(简化)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)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
products.productmodel:'productDownloads'与模型productModelDownLoad有一个m2m关系,它没有安装或者是抽象的.
我在django文档中找到了一个似乎可以解决这个问题的页面,但我无法理解它的含义:http: //www.djangoproject.com/documentation/models/invalid_models/
该模型看起来对我有用,那么这里的问题是什么?
有趣的是,有两种方法可以解决这个问题:
a)Thomas 的答案可以解决这个问题,
b)但是,Mike Korobov 的答案也可以:
关系中的字段名称中有一个杂散的大写字母:
ProductDownloads = models.ManyToManyField('productModelDown* L *oad')
纠正这种杂散资本也可以解决这个问题。
| 归档时间: |
|
| 查看次数: |
10591 次 |
| 最近记录: |