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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:57:56+00:00 2026-05-31T00:57:56+00:00

I am using Django 1.3/Python 2.7. My application is using django.contrib.auth for User management.

  • 0

I am using Django 1.3/Python 2.7.

My application is using django.contrib.auth for User management. For the main user registration I have a form which checks if the ’email’ has already been registered. So it makes sure all email fields are unique.

But it happens that some admins use the django admin interface to add users, and end up adding duplicate accounts with the same email.

For this purpose I have created a NewUserCreationForm, where I’ve duplicated the django.contrib.auth.UserCreationForm and added an ’email’ field to it.

class NewUserCreationForm(forms.ModelForm):
    """                                                                                                                                                                                                             
    A form that creates a user, with no privileges, from the given username and password.                                                                                                                           
    """
    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.")})
    password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
    password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput,
        help_text = _("Enter the same password as above, for verification."))
    email = forms.EmailField(label=_("Email"), max_length=75)

    class Meta:
        model = User
        fields = ("username", "email")

    def clean_username(self):
        username = self.cleaned_data["username"]
        try:
            User.objects.get(username=username)
        except User.DoesNotExist:
            return username
        raise forms.ValidationError(_("A user with that username already exists."))

    def clean_password2(self):
        password1 = self.cleaned_data.get("password1", "")
        password2 = self.cleaned_data["password2"]
        if password1 != password2:
            raise forms.ValidationError(_("The two password fields didn't match."))
        return password2

    def save(self, commit=True):
        user = super(NewUserCreationForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password1"])
        user.email = self.email
        if commit:
            user.save()
        return user


class CustomUserAdmin(UserAdmin):
    add_form = NewUserCreationForm


admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)

But this code isn’t working. I can see the form rendering, but with no email field, just the Username, password1 and password2 fields.

what is it that I am missing here?

  • 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-31T00:57:57+00:00Added an answer on May 31, 2026 at 12:57 am

    You are missing … UserAdmin.add_fieldsets, e.g.:

    class CustomUserAdmin(UserAdmin):
        add_form = NewUserCreationForm
        add_fieldsets = (
            (None, {
                'classes': ('wide',),
                'fields': ('username', 'password1', 'password2', 'email')}
            ), 
        )  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple mail sending application which runs in python using Django. After
I have python threaded application + Postgres. I am using Django's ORM to save
I have a web application im currently working on in python. I'm using Django
I am working on a web application using Python (Django) and would like to
I'm using Django and Python 2.6, and I want to grow my application using
When starting a django application using python manage.py shell , I get an InteractiveConsole
I am trying to make an chat application using python and django. I almost
I'm using Django to create registration/payment application for a limited number of products. I
I have a django application using mod_python, fairly typical configuration except that media files
i have made an application using python and google app engine, the app works

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.