Is is possible to have 2 models to store extra user details. I ask because I'm currently writing an app which i want to plug into a few existing projects. However all these projects already use a profile model, and my new app needs to extend the user model through the profile model. If it isn't is there a way of extending the currently in use profile model set within AUTH_PROFILE_MODULE?
1 Answer
Shouldn't you just create a field in this other model that has a foreign key to the profile?
So assuming you have an already existent UserProfile model.
Class UserProfile(models.Model):
user = models.OneToOneField(User)
...
You could extend the UserProfile model by adding a foreign key in your other model, linking to it.
Class OtherModel(models.Model):
profile = models.ForeignKey(UserProfile, related_name="other_model")
field1 = models.CharField(max_length=15)
...
And so you can access this other model from the User object:
user.get_profile().other_model.field1
HTH
-
Any idea how to import the user model without knowing the path? Possibly by using django.conf.AUTH_PROFILE_MODULE?– dottyJan 10, 2011 at 11:00