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 8437907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:33:44+00:00 2026-06-10T07:33:44+00:00

I have a form where users get edit their personal information/settings and I’m trying

  • 0

I have a form where users get edit their personal information/settings and I’m trying to get it to pre-populate if they have entered that information in the past. I looked here:

Django prepopulate form with the fields from the database

for help, but still can’t get the form to prepopulate. Thanks in advance.

#model

    class UserProfile(models.Model):

        user = models.OneToOneField(User)
        activation_key = models.CharField(max_length=40, blank=True)
        first_name = models.CharField(max_length=50, blank=True)
        last_name = models.CharField(max_length=50, blank=True)
        phone_number = PhoneNumberField(blank=True, null=True)
        address_line_1 = models.CharField(max_length=300, blank=True)
        address_line_2 = models.CharField(max_length=300, blank=True)
        address_line_3 = models.CharField(max_length=300, blank=True)
        city = models.CharField(max_length=150, blank=True)
        postalcode = models.CharField(max_length=10, blank=True)
        paypal_email = models.EmailField(max_length=75, blank=True)
        photo = models.ImageField(upload_to="images/", blank=True)


        def __unicode__(self):
            return self.user.username

        def save(self, *args, **kwargs):
            try:
                existing = UserProfile.objects.get(user=self.user)
                self.id = existing.id #force update instead of insert
            except UserProfile.DoesNotExist:
                pass 
            models.Model.save(self, *args, **kwargs)


    #form
    class UserProfileForm(forms.ModelForm):

        class Meta:
            model = UserProfile
            exclude = ('user', 'activation_key',)

    # view
    def update_settings(request):
        if request.method== 'POST':
            try:
                u = UserProfile.objects.get(user=request.user)
                form = UserProfileForm(request.POST, instance=u)
            except ObjectDoesNotExist:
                form = UserProfileForm(request.POST, request.FILES)
            if form.is_valid:
                profile = form.save(commit=False)
                profile.user = request.user
                profile.save()
                return HttpResponseRedirect('registration/activation_complete.html')
        else:
            try:
                u = UserProfile.objects.get(user=request.user)
                form = UserProfileForm(request.POST, instance=u)
            except ObjectDoesNotExist:
                form = UserProfileForm(request.POST, request.FILES)
            return render_to_response('registration/update_settings.html', locals(), context_instance=RequestContext(request))
  • 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-06-10T07:33:45+00:00Added an answer on June 10, 2026 at 7:33 am

    You can update your view code like this:

    def update_settings(request):
        if request.method== 'POST':
            try:
                u = UserProfile.objects.get(user=request.user)
                form = UserProfileForm(request.POST, instance=u)
            except ObjectDoesNotExist:
                form = UserProfileForm(request.POST, request.FILES)
            if form.is_valid():  #is_valid is function not property
                profile = form.save(commit=False)
                profile.user = request.user
                profile.save()
                return HttpResponseRedirect('registration/activation_complete.html')
        else:
            try:
                u = UserProfile.objects.get(user=request.user)
                form = UserProfileForm(instance=u) #No request.POST
            except ObjectDoesNotExist:
                form = UserProfileForm(request.FILES)
       # move it outside of else
       return render_to_response('registration/update_settings.html', locals(),
                     context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form where users can store and edit their skills in different
I have a template which allows the user to edit their user information. <form
I have a form which users can add controls to and when they right
I have a form in witch users can add their working hours view them
I have users fill out their profile information somewhere on my site using the
I have trying to allow a user to edit their account (simple enough, eh?)
I am using this edit form to let users edit their posts/notes etc. And
I have a view that enables users to edit their profiles (usual name, username
I have a form which users must fill out and submit. The controller action
I have a form where users can modify a collection of objects using a

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.