I’ve linked a UserProfile to a user. However, I do not like having to jump back and forth in the templates to get first_name, last_name, etc. I would like to use the User model for only auth-related stuff, and UserProfile for all information related to the user (mostly, the display of the user information).
I was wondering if someone could evaluate how my current UserProfile model is, and where I could improve it or where it is redundant, etc. Thank you.
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
network = models.ForeignKey(Network)
location = models.CharField(max_length=100, blank=True)
graduation = models.IntegerField(blank=True, null=True, choices=YEAR)
headline = models.CharField(max_length=100, blank=True,)
positions = models.ManyToManyField(Position, through ='Timestamp', blank=True)
bio = models.TextField(max_length=1000, blank=True)
@property
def get_first_name(self):
return self.user.first_name
@property
def get_last_name(self):
return self.user.last_name
def get_full_name(self):
return self.user.get_full_name
@property
def get_date_joined(self):
return self.user.date_joined
Don’t use the “get” prefix on properties. Also, don’t forget that you can’t query on properties, so you’ll need to join to
Userfor those. Perhaps you may want to add some custom queries to your manager for that.