With Django 1.1, which is currently in beta, I would use a proxy model.
class MyUser(User): class Meta: proxy = True def get_profile(self): if self.role == 'professor': return ProfessorProfile._default_manager.get(user_id__exakt=self.id) elif self.role == 'student': return StudentProfile._default_manager.get(user_id__exakt=self.id) else:
get_profile needs a caching code from the original and so on. But essentially you could do something like this.
With Django 1.0.x, you can implement derived classes based on User, but this can break code in other places. For such things, I like proxy classes that simply add python functionality without changing database models.
Oliver andrich
source share