from django.db import models class Person(models.Model): """Demonstrate model attribute with a Python property >>> p = Person(firstName='Jeff', lastName='Bauer') >>> p.name 'Bauer, Jeff' >>> """ firstName = models.CharField(maxlength=20) lastName = models.CharField(maxlength=20) middleName = models.CharField(maxlength=20, blank=True) def _name(self): if self.middleName: return "%s, %s %s." % (self.lastName, self.firstName, self.middleName[:1]) else: return "%s, %s" % (self.lastName, self.firstName) name = property(_name)