User is not added successfully after creating a custom User model

What happened

What happened is

  1. Create a custom User model by inheriting the Abstract User model.
  2. Register normally with admin like admin.register.site (CustomUser) **
  3. Register a new User from the admin administration screen!
  4. For some reason, the password is displayed raw.
  5. I can't log in! !! !!

The problem has occurred. .. From the conclusion, the cause is operation 2.

By the way, you can read more about customizing Users in the following articles. Article by okoppe8

Solution

Register UserAdmin in the second argument of admin.site.register ().

admin.py


from django.contrib import admin

from . models import CustomUser
from django.contrib.auth.admin import UserAdmin
)


admin.site.register(CustomUser, UserAdmin)

Original code

I created UserAdmin by myself to customize the management screen and registered it as admin of CustomUser model. If this is the case, the password will not be hashed properly and will be registered, resulting in an error during authentication.

admin.py


from django.contrib import admin

from . models import CustomUser


class UserAdmin(admin.ModelAdmin):
    list_display = ('username', 'id', )


admin.site.register(CustomUser, UserAdmin)


reference

Stuck Overflow Created User from django custom admin page can't login

Recommended Posts

User is not added successfully after creating a custom User model
What is a dog? Django--Create a custom user model
What is a dog? Django--Create a custom user model 2
Implement a Custom User Model in Django
[Day 9] Creating a model
[Django] No changes detected even if make migrations is executed after creating a Model
Python list is not a list
What is a super user?
Creating a Tensorflow Sequential model with original images added to MNIST
Creating a learning model using MNIST
[My note] Django's custom User model