我正在构建一个具有嵌套树分类的模型。词汇表Entity
继承自抽象基类TreeVocabulary
。还有一个类SpecialEntity
,它继承自Entity
. SpecialEntity
里面应该有几个额外的字段。
Entity
并且SpecialEntity
都应该是树,为此我使用 mptt http://django-mptt.github.com/django-mptt/。其中Entity
应该有一个记录,其中有子SpecialEntity
元素(这些子元素是 中的根元素SpecialEntity
)。
这就是我的想象:
class Vocabulary(models.Model):
name= models.CharField(max_length=300)
order= models.IntegerField(default=100)
class Meta:
abstract= True
class SpecialType(Vocabulary):
class TreeVocabulary(MPTTModel):
parent= TreeForeignKey('self', null=True, blank=True,
related_name='children', limit_choices_to=Q(parent__isnull=True))
class MPTTMeta:
order_insertion_by= ('name',)
class Meta:
abstract= True
class Entity(TreeVocabulary):
class SpecialEntity(Entity):
code= models.CharField(max_length=50)
type= models.ForeignKey(SpecialType)
class Meta:
ordering= ('code',)
现在,问题是由于某种原因SpecialEntity
转义了 mptt:sqlall
显示了一个没有其中的普通表parent_id
。虽然它存在于 中Entity
,但它直接继承自TreeVocabulary
.
它是 django-mptt 中的错误吗?或者也许这是一个糟糕的设计?我不是要求为我设计它,而是指出正确的方向
提前致谢!