I'm trying to implement a multi-table inheritance class hierarchy in Django (1.7).
My models can be simplified to these:
PARTY_TYPES = ((1, "Person"), (2, "Organization"))
ORGANIZATION_TYPES = ((1, "Private"), (2, "Governmental"))
class Party(models.model):
party_type = models.PositiveSmallIntegerField(choices = PARTY_TYPES)
party_name = models.CharField(max_length = 250)
class Person(Party):
sex = models.CharField(max_length = 1)
class Organization(Party):
organization_type = models.PositiveSmallIntegerField(choices = ORGANIZATION_TYPES)
full_name = models.CharField(max_length = 250)
class PrivateOrganization(Organization):
some_field = ...
class GovernmentalOrganization(Organization):
some_field = ...
As you can see there's a 2-level-deep inheritance hierarchy. When the party is imported as a foreign key to some other model, a user needs to be able to add it by clicking the add button next to the field. That's where my problem begins. I need to ask the user the king of party to add, then possibly the kind of organization to add, then present the correct form. I've spent some hours with good posts like this or this and had partial success but I could not implement a proper solution. There are other multiple-level deep inheritance cases in my project, so solving this problem is really important for me. I'd appreciate any "best practice" advice.