通过 add_to_class() 添加字段时,我的模型继承存在问题。我有一个模型File(models.Model)
-Image(File)
这些来自 django-filer。
在我的应用程序中,我正在导入它们并添加字段和方法:
def method_x(self):
print "x"
File.add_to_class("expiration_date", models.DateField(null=True, blank=True))
File.add_to_class("method_x", method_x)
图像应该继承这两者,但它只获取方法,而不是字段:
>>> some_file = File.objects.get(id=8)
>>> some_image = Image.objects.get(id=8)
>>>
>>> print some_file.expiration_date # this works
... None
>>>
>>> some_image.metgod_x() # this works
>>> x
>>>
>>> print some_image.expiration_date # and this not
Traceback (most recent call last):
File "<console>", line 1, in <module>
AttributeError: 'Image' object has no attribute 'expiration_date'
有什么线索吗?