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

  • Home
  • SEARCH
  • 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 6538651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:45:39+00:00 2026-05-25T10:45:39+00:00

I have a custom ChangeUserForm (ModelForm on User) that allows a user to update

  • 0

I have a custom ChangeUserForm (ModelForm on User) that allows a user to update their account information.

However, when I save the form, user.is_active, user.is_staff and user.is_superuser all get set to False.

Any thoughts on what’s going on here?

forms.py

class UserChangeForm(forms.ModelForm):
    username = forms.RegexField(label="Username", max_length=30, regex=r'^[\w.@+-]+$',
        help_text = "Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.",
        error_messages = {'invalid': "This value may contain only letters, numbers and @/./+/-/_ characters."})
    first_name = forms.CharField(label="First name", max_length=30)
    last_name = forms.CharField(label="Last name", max_length=30)
    email = forms.EmailField(label="E-mail Address")
    new_password1 = forms.CharField(label="New password", widget=forms.PasswordInput, required=False)
    new_password2 = forms.CharField(label="Confirm new password", widget=forms.PasswordInput, required=False)

    class Meta(auth_forms.UserChangeForm):
        model = User
        exclude = ('password', 'last_login', 'date_joined')

    def clean_new_password2(self):
        password1 = self.cleaned_data.get('new_password1')
        password2 = self.cleaned_data.get('new_password2')

        if password1 != password2:
            raise forms.ValidationError("The two password fields didn't match.")
        else:
            if len(password2) > 0 and len(password2) < 8:
                raise forms.ValidationError("Your password must be a minimum of 8 characters.")
        return password2

    def save(self, commit=True):
        user = super(UserChangeForm, self).save(commit=False)
        if len(self.cleaned_data['new_password2']) > 0:
            user.set_password(self.cleaned_data['new_password2'])
        if commit:
            user.save()
        return user

    class UserProfileForm(forms.ModelForm):
        class Meta:
            model = UserProfile
            exclude = ('user')

views.py

@login_required
def profile(request):
    context = {}
    if request.method == 'POST':
        user_form = UserChangeForm(request.POST, instance = request.user)
        user_profile_form = UserProfileForm(request.POST, instance = request.user.profile)
        if user_form.is_valid() and user_profile_form.is_valid():
            user_form.save()
            user_profile_form.save()

            return render_to_response('accounts_profile_complete.html', context_instance=RequestContext(request))
    else:
        user_form = UserChangeForm(instance = request.user)
        user_profile_form = UserProfileForm(instance = request.user.profile)
    context.update(csrf(request))
    context['user_form'] = user_form
    context['user_profile_form'] = user_profile_form

    return render_to_response('accounts_profile.html', context, 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-05-25T10:45:40+00:00Added an answer on May 25, 2026 at 10:45 am

    Just a guess: they aren’t on the exclusion list in the Meta class so they’re being set to false (boolean fields like those use a checkbox, which doesn’t show up in POST data when unchecked). The form can’t tell the difference between a boolean form field set to false and one that isn’t on the page in the first place so you need to explicitly exclude them.

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

Sidebar

Related Questions

Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
I have a few models that need to have custom find conditions placed on
I have a custom validation function in JavaScript in a user control on a
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).
I have a custom installer action that updates the PATH environment, and creates an
We have a custom-built Flash-based video player that I maintain, and it needs to
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have custom slider that I use the following touch event to respond to:
I have custom JSP tags that generate some HTML content, along with some javascript
I have custom components which must adjust their text content based on space constraints.

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.