Django: Extending User Model - Inline User fields in UserProfile

Posted by Jack Sparrow on Stack Overflow See other posts from Stack Overflow or by Jack Sparrow
Published on 2012-10-11T15:45:46Z Indexed on 2012/10/11 21:37 UTC
Read the original article Hit count: 233

Filed under:
|
|

Is there a way to display User fields under a form that adds/edits a UserProfile model? I am extending default Django User model like this:

class UserProfile(models.Model):
    user = models.OneToOneField(User, unique=True)
    about = models.TextField(blank=True)

I know that it is possible to make a:

class UserProfileInlineAdmin(admin.TabularInline):

and then inline this in User ModelAdmin but I want to achieve the opposite effect, something like inverse inlining, displaying the fields of the model pointed by the OneToOne Relationship (User) in the page of the model defining the relationship (UserProfile). I don't care if it would be in the admin or in a custom view/template. I just need to know how to achieve this.

I've been struggling with ModelForms and Formsets, I know the answer is somewhere there, but my little experience in Django doesn't allow me to come up with the solution yet. A little example would be really helpful!

© Stack Overflow or respective owner

Related posts about python

Related posts about django