You could make your models all inherit a new model that has a property
function defined to get/set the right variable.
class BaseNameClass(models.Model)
def getfname(self):
if hasattr(self, 'first_name'): return self.first_name
if hasattr(self, 'prenom'): return self.prenom
if hasattr(self, 'forename'): return self.forename
def setfname(self, x):
if hasattr(self, 'first_name'): self.first_name = x
if hasattr(self, 'prenom'): self.prenom = x
if hasattr(self, 'forename'): self.forename = x
firstname = property(getfname, setfname)
And then change your models to all inherit from that. It will be slightly slower but we're talking nano and milliseconds.
If you had an descendant object called person
, you'd access the name simply by:
print person.firstname
person.firstname = "oli"
print person.firstname