Hi All I have a load of Institutions, some with departments, some not. So I created a model that can represent this simple hierarchy. See models at the bottom.
Fine, but a bit confusing for users, plus if the user just wants to deal with Institutions alone in the admin, they're faced with institutions and departments. I'm relying heavily on the admin app in my project btw. So, I've tried having two models - InstitutionDepartment and Institution that have the same table but different managers- (see below). Institution doesn't use the "parent" foreign key. (Btw I haven't used inheritance here cos copy and paste is quick and dirty.) I also have an Address model and JobPosition model that depend on "institution_department_id", therefore to make this work, I'll need two Address models with the same table? I've tried this and it works, it's just v messy! Is there a better way to do this?? >From my point of view it would just be much easier to have multiple ModelAdmin classes use a single Model, but I can't do this can I? Cheers Will T class InstitutionDepartment(models.Model): TYPE_CHOICES = ( ('I', 'Institution'), ('D', 'Department'), ) institution_department_id = models.AutoField(primary_key=True) name = models.CharField(max_length=200) acronym = models.CharField(max_length=10, null=True, blank=True) type = models.CharField(max_length=1, choices=TYPE_CHOICES) parent = models.ForeignKey('self', null=True, blank=True) def __unicode__(self): if self.parent: return ' | '.join([self.parent.name, self.name, ]) else: return self.name class Meta: db_table = 'institution_department' ordering = ['parent__name', 'name', ] class Institution(models.Model): TYPE_CHOICES = ( ('I', 'Institution'), ('D', 'Department'), ) institution_department_id = models.AutoField(primary_key=True) name = models.CharField(max_length=200) acronym = models.CharField(max_length=10, null=True, blank=True) objects = InstitutionManager() type = models.CharField(max_length=1, choices=TYPE_CHOICES) def __unicode__(self): return self.name class Meta: db_table = 'institution_department' class StreetAddress1(StreetAddressAbstract): institution_department = models.OneToOneField(InstitutionDepartment) class Meta(StreetAddressAbstract.Meta): pass class StreetAddress2(StreetAddressAbstract): institution_department = models.OneToOneField(Institution) class Meta(StreetAddressAbstract.Meta): pass --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---