[Django]-Django Foreign Keys Breaking with Multi-Table Inheritance

0👍

It should work if you define your Officer model explicitly as abstract

class Meta:
    abstract = True

So as a test i slightly modified your base class:

class Officer(models.Model):
    name = models.CharField(max_length=255)
    class Meta:
       abstract = True

And the following works:

>>> General(name='Warfield').save()
>>> G = General.objects.all()[0]
>>> Captain(name='Picard', general=G).save()
>>> C = Captain.objects.all()[0]    
>>> C.general.name
u'Warfield'
>>> G.captains.all()[0].name
u'Picard'
👤arie

Leave a comment