Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6603393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:00:16+00:00 2026-05-25T19:00:16+00:00

I’ve extended the standard Django User model with a UserProfile, and created a OneToOne

  • 0

I’ve extended the standard Django User model with a UserProfile, and created a OneToOne relationship from the UserProfile to the User, like so:

class UserProfile(models.Model):
    user = models.OneToOneField(adminmodels.User)
    about = models.TextField('About the author', blank=True)
    picture = models.ImageField('Picture (70px x 70px)', blank=True, upload_to='uploads/profile_pics', default='noone.png')
    user_site = models.URLField(blank=True, verify_exists=False)

class Meta:
    verbose_name = "Profiel"
    verbose_name_plural = "Profielen"

To get the corresponding admin form included in the User admin, I created an inline admin form, and added it to the user admin, like so:

# Inline admin for the user profile
class UserProfileInline(admin.StackedInline):
    model = UserProfile
    fk_name = 'user'
    max_num = 1
    extra = 0

# Include the extra form
class MyUserAdmin(admin.ModelAdmin):
      inlines = [UserProfileInline, ]

# Re-register the user form
admin.site.unregister(admin.models.User)
admin.site.register(admin.models.User, MyUserAdmin)

Than, lastly, to save an instance of UserProfile, I have a function connected to postsave. It looks like this:

def on_user_was_saved(sender,instance,created,using,*args,**kwargs):
    if type(instance) == adminmodels.User:    
        if created:
            profile = UserProfile.objects.get_or_create(user = instance)
            profile.save()
        else:
            profile = UserProfile.objects.get_or_create(user = instance)
            profile[0].save()

Now, two things go wrong:

  1. When saving the user with anything in the user profile field, the user is saved, and so is the instance of UserProfile, but the instance has been saved as if all fields were empty. When entering something new in these fields you can save that though, nothing goes wrong than.
  2. A second instance of the UserProfile form becomes available; max_num is ignored.

After benjaoming’s input I’ve changed my post_save callback to:

    try:
        profile = UserProfile.objects.get(user = instance)
        profile.save()
    except:
        profile = UserProfile.objects.get_or_create(user = instance)
        profile[0].save()

However this doesn’t solve either of the problems I already had.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:00:17+00:00Added an answer on May 25, 2026 at 7:00 pm

    The main issue here is that you’re not actually processing the profile form. Look at the code you’ve written: at no point do you have anything to take the values that you’ve entered for the user profile and save them to the database.

    Also, admin.StackedInline is not built for the purpose you’re trying to use it for. That manages one-to-many relationships, not one-to-one relationships.

    If you must have the functionality in the admin follow exactly the setup that you are outlining, probably your best shot is to add a custom view to AdminSite with the forms for adding and editing users. Alternatively, have people edit two forms to create a user.

    Anyway, you can read more about adding views to an AdminSite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.