0

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?

0

1 Answer 1

1

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

1
  • Any idea how to import the user model without knowing the path? Possibly by using django.conf.AUTH_PROFILE_MODULE?
    – dotty
    Jan 10, 2011 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.