1
有了这个代码:如何用抽象模型定义外键关系?
class Part:
name = models.CharField(
_("Name of part"),
max_length=255,
help_text=_("Name of the part.")
class Meta:
verbose_name = _("Part")
verbose_name_plural = _("Parts")
abstract = True
class Book(Part):
isbn = models.CharField(
help_text=_("The ISBN of the book"),
max_length=15
)
我的模型。我下一步我需要链接到基本对象。
class StorageItem(models.Model):
part = models.ForeignKey(
Part,
help_text=_("The part stored at this spot.")
)
我得到这个错误消息::
ERRORS:StorageItem.part:(fields.E300)字段定义 与模型 '部件' 的关系,这与此代码完成要么没有安装,要么是抽象的 。
将对象链接到一组不同类的所有派生自一个基类的正确方法是什么?
它看起来像django_polymorphic是我最后寻找的。不确定是否会在几个月内成为最好的,但到目前为止;) – frlan