Django Models: Common Ancestor Inheritance & Migration

前端 未结 1 1516
渐次进展
渐次进展 2021-01-25 00:12

I thought I would up my python game with Django a bit by developing a large scale business app for fun. I seen the need for a common ancestor approach

相关标签:
1条回答
  • 2021-01-25 00:52

    Since your parent model is intended to be abstract, you should mark it as such.

    class BusinessEntity(models.Model):
        title = models.CharField(max_length=180)
    
        class Meta:
            abstract = True
    

    This prevents Django from creating a separate table for it, and therefore needing a _ptr field to point back to it from the subclass. Instead, the table for your subclass will be created to include the inherited field(s) directly.

    0 讨论(0)
提交回复
热议问题