0

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.

Community
  • 1
  • 1
Can Aksu
  • 1
  • 2
  • Is this a case of "(inheritance) is like violence: if it's not working, just use more"? – Daniel Roseman Sep 28 '14 at 14:26
  • I have an MS-Access background. I'm new to OOP, but in the relational database world, it makes a lot of sense to divide an entity to sub-tables, in an "is-a" fashion. I implemented my project successfully there, now I'm trying to migrate. I used intermediary "wizard forms" in Access, now I'm looking for the equivalent practice in Django. – Can Aksu Sep 28 '14 at 17:03

0 Answers0