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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:39:54+00:00 2026-06-07T02:39:54+00:00

i’m using Django registration, and unlike everybody else, I seem to have the opposite

  • 0

i’m using Django registration, and unlike everybody else, I seem to have the opposite problem. My User object is saved fine, but my UserProfile object isn’t!

I followed this website:

http://birdhouse.org/blog/2009/06/27/django-profiles/

which was really good, and so now i have:

class ProfileForm(forms.ModelForm):

    YESNO = [
        (True,mark_safe('<img src="/static_files/greenTick.png"/>')),
        (False,mark_safe('<img src="/static_files/redCross.png"/>'))]

    class Meta:
        model = UserProfile
        exclude = ('isTweeting','points','user')
        fields = ('display_name','first_name','last_name','email','gravatar')

    def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        self.fields['email'].initial = self.instance.user.email
        self.fields['first_name'].initial = self.instance.user.first_name
        self.fields['last_name'].initial = self.instance.user.last_name
        self.fields['display_name'].initial = self.instance.user.username
        self.fields['gravatar'].initial = self.instance.usesGravatar

    #add in the input to size it juuuuust right.
    email = forms.EmailField(label="Primary email",help_text='',widget=forms.TextInput(attrs={'class': 'wideInput'}))
    first_name = forms.Field(label="First name",help_text='',required=False,widget=forms.TextInput(attrs={'class': 'wideInput'}))
    last_name = forms.Field(label="Last name",help_text='',required=False,widget=forms.TextInput(attrs={'class': 'wideInput'}))
    display_name = forms.Field(label="Display name",help_text='',widget=forms.TextInput(attrs={'class': 'wideInput'}))
    gravatar = ImgModelChoiceField(label='Gravatar', choices=YESNO, widget=forms.RadioSelect(renderer=ImgRadioFieldRenderer))

    def save(self, *args, **kwargs):
        """
        Update the primary email address on the related User object as well.
        """
        u = self.instance.user
        u.email = self.cleaned_data['email']
        u.username = self.cleaned_data['display_name']
        u.first_name = self.cleaned_data['first_name']
        u.last_name = self.cleaned_data['last_name']
        u.save()

        self.instance.gravatar = (self.cleaned_data['gravatar'] == 'True')
        profile = super(ProfileForm, self).save(*args,**kwargs)
        return profile

this object is passed into the Django-profile as the form_class for use, as described in the website above. The problem i have is that when i submit my form, while the “User” data is updated correctly – any changes in the email or whatnot propagate to the db – the change to the “gravatar” value is not sent. Also no error is thrown.

Any ideas what I should do?

  • 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-07T02:39:56+00:00Added an answer on June 7, 2026 at 2:39 am

    I’m going to hazard a guess here

    def save(self, *args, **kwargs):
        ...
    
        self.instance.gravatar = (self.cleaned_data['gravatar'] == 'True')
        profile = super(ProfileForm, self).save(*args,**kwargs)
        return profile
    

    It seems you are using a custom widget, and by the looks of things you need to change the string 'True' (passed back from the form) to a boolean True before saving it to the DB. When you call save() on the next line though, the ModelForm will overwrite the value you have given self.instance.gravatar with the data directly from the form’s cleaned_data:

    https://github.com/django/django/blob/master/django/forms/models.py#L351


    Also, in __init__, you don’t need to include

    self.fields['gravatar'].initial = self.instance.usesGravatar
    

    as this field is already bound to the model form and will be automatically populated (if the UserProfile is being edited for example) when you instantiate the form along with an instance in your view.


    Finally, in your Meta, you don’t need to include both excludes and fields, one or the other should be fine.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the

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.