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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:25:30+00:00 2026-06-15T10:25:30+00:00

I extend the django user model as described in the dev doc. I wan’t

  • 0

I extend the django user model as described in the dev doc. I wan’t to keep most of the original User model features so I extend the AbstractUser class. I’ve defined in settings.py:

AUTH_USER_MODEL = 'myapp.CustomUser'

My user class:

class CustomUser(AbstractUser):
  custom_field = models.ForeignKey('OtherModel')
  objects = UserManager()

Everything seems to work fine but when I try to make it managed by the admin site:

admin.site.register(CustomUser, UserAdmin)

I get this error on the admin CustomUser creation page (after validation of the password confirmation form):

AttributeError: Manager isn't available; User has been swapped for 'myapp.CustomUser'

The point is that I need this model managed by the admin site in order to have the same creation process as with the original User model (two step process with password validation).

  • 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-15T10:25:31+00:00Added an answer on June 15, 2026 at 10:25 am

    You need only change form for adding user(overwrite clean_username and change User on get_user_model()

    Full working example(If you inherited from AbstractUser)

    from django.contrib.auth import get_user_model
    from django.contrib.auth.admin import UserAdmin
    from django.contrib.auth.forms import UserCreationForm, UserChangeForm
    
    
    class MyUserChangeForm(UserChangeForm):
    
        class Meta:
            model = get_user_model()
    
    class MyUserCreationForm(UserCreationForm):
    
        class Meta:
            model = get_user_model()
    
        def clean_username(self):
            username = self.cleaned_data["username"]
            try:
                get_user_model().objects.get(username=username)
            except get_user_model().DoesNotExist:
                return username
            raise forms.ValidationError(self.error_messages['duplicate_username'])
    
    class MyUserAdmin(UserAdmin):
        form = MyUserChangeForm
        add_form = MyUserCreationForm
        fieldsets = (
            (None, {'fields': [('username', 'password'),]}),
            (_('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
            (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
                                       'groups', 'user_permissions')}),
            (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
            )
    
    admin.site.register(MyUser, MyUserAdmin)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a custom user model as described in the django docs.
I'm getting started with django and I'd like to extend the basic django.contrib.auth.models.User class
I'm attempting to extend django's contrib.auth User model, using an inline 'Profile' model to
I know it's very standard to extend Django's User class with your own UserProfile
I'm trying to extend the User model in Django using inheritance. Here's my model:
I have django model: class UserProfile(models.Model): user = models.OneToOneField(User) #other fields When I create
So im wanting to extend the django auth.User model to add extra fields. Ive
What's the best way to extend the User model (bundled with Django's authentication app)
Scenario: Let's say I want to extend Django's User model using multi-table inheritance. Let's
How would one extend the Paginator class in django.core.paginator to work with Google App

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.