class Party(models.Model):
address = models.TextField()
class Company(Party):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class Person(Party):
fname = models.CharField(max_length=100)
lname = models.CharField(max_length=100)
company = models.ForeignKey(Company, null=True, blank=True)
def __unicode__(self):
return "%s %s" % (self.lname, self.fname)
В голову приходит следующая мысль
def __unicode__(self):
try:
return self.company.__unicode__()
except:
return self.person.__unicode__()