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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:28:19+00:00 2026-06-06T09:28:19+00:00

I have an app with 2 user levels; Superuser, and Staff. Superuser will login

  • 0

I have an app with 2 user levels; Superuser, and Staff. Superuser will login to this app and create a new user and assign the user either Superuser or Staff permissions, but they are not logging in through the default Django admin, they will be logging into a custom admin. How do I display the permission checkboxes in my form and how do I save them for that new user being created? Is it merely just a normal checkbox or is there something I need to override to be able to accomplish this?

Here is my CreateUserForm as it is now.

class CreateUserForm(forms.Form):
    username = forms.EmailField(max_length=50)
    email = forms.EmailField()
    first_name = forms.CharField(max_length=150)
    last_name = forms.CharField(max_length=150)
    password1 = forms.CharField(max_length=30, widget=forms.PasswordInput(render_value=False), label='Password')
    password2 = forms.CharField(max_length=30, widget=forms.PasswordInput(render_value=False), label='Password Confirmation')
    address_1 = forms.CharField(max_length=50)
    address_2 = forms.CharField(max_length=50)
    city = forms.CharField(max_length=50)
    province = forms.CharField(max_length=2)
    country = forms.CharField(max_length=50)
    postal_code = forms.CharField(max_length=10)
    work_phone = forms.CharField(max_length=20)
    mobile_phone = forms.CharField(max_length=20)
    fax = forms.CharField(max_length=20)
    url = forms.CharField()
    comments = forms.CharField(widget=forms.Textarea)

    def clean_username(self):
        try:
            User.objects.get(username=self.cleaned_data['username'])
        except User.DoesNotExist:
            return self.cleaned_data['username']
        raise forms.ValidationError("Sorry, this username has already been taken. Please choose another.")

    def clean_email(self):
        try:
            User.objects.get(email=self.cleaned_data['email'])
        except User.DoesNotExist:
            return self.cleaned_data['email']
        raise forms.ValidationError("Sorry, this email has already been taken. Please choose another.")

    def clean(self):
        if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
            if self.cleaned_data['password1'] != self.cleaned_data['password2']:
                raise forms.ValidationError("You must type the same password each time.")
            if ' ' in self.cleaned_data['username']:
                raise forms.ValidationError("username must not contain spaces")
        return self.cleaned_data

    def save(self):
        new_user = User.objects.create_user(
            username = self.cleaned_data['username'],
            email = self.cleaned_data['email']
        )
        new_user.first_name = self.cleaned_data['first_name']
        new_user.last_name = self.cleaned_data['last_name']
        new_user.set_password(self.cleaned_data['password'])
        new_user.is_active = True
        new_user.save()

    new_profile = UserProfile(
        # TODO:
    )

Thanks

  • 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-06T09:28:20+00:00Added an answer on June 6, 2026 at 9:28 am

    If you mean the permission checkboxes for is_staff and is_superuser, then you’re probably best off using a ModelForm w/ the User model. This will automatically take care of everything for you.

    class UserForm(forms.ModelForm):
        class Meta:
            model = User
            exclude = ('last_login', 'date_joined')
    

    EDIT per OP update: You can just add 2 forms.BooleanField() fields to your form for is_superadmin and is_staff (or name them differently), and much like you’re already doing in the save method you can do new_user.is_staff = self.cleaned_data['is_staff']. You may consider using a choice field instead, w/ a dropdown w/ 3 entries, “Normal User”, “Staff User”, “Admin User”, and then set is_staff and is_superadmin according to the user’s selection.

    It’s also still possible to use a ModelForm on the User model and just add the necessary extra fields in addition. It may or may not be worth it to you, depending how custom you’re getting.

    Another note about your form – when it comes to editing existing users, this won’t be able to be used for that w/ the current clean methods on username/email. But if you tweak those to exclude the current instance (if set) from the lookup, you will be able to use this form for editing existing users (though since it’s not a model form you’d need to populate the initial data manually).

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

Sidebar

Related Questions

Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
I have a flex app which allows user to create some content. this content
We are developing a web app that will have a pretty complex user and
I have an app that requires user to register. I've got the app conected
I have a winforms app that checks user credentials as it starts. If autharization
I have created an app to standardize user creation for our AD domain. Now
I have an app that allows the user to choose an image, at design
I have an app that allows the user to choose a picture from their
I have an app that can open up some other forms at the user's
So I have an app that plays a bunch of songs while the user

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.