Reputation: 303
I am trying to inherit from AbstractUSer my models.py looks like:
class MyUser(AbstractUser):
created = models.DateTimeField(auto_now_add=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username',]
MyUser._meta.get_field_by_name('email')[0]._unique=True
now by declaring email as unique field and username as a required field my superuser is being created successfully and also is being authenticated properly but I am having a problem while creating any other user as if I am creating any user through my admin page its not being authenticated.It always returns
None
My admin.py:
from django.contrib import admin
from credilet.models import *
admin.site.register(MyUser)
What I am thinking is that the create_user is not being called properly as if I see in my admin page the password is not hashed so that means the create_user is not being called properly.Somebody please help through it or even if you have a proper documentation on abstractuser
not abstractbaseuser
so please refer that to me in the solutions.
Thanks
Upvotes: 2
Views: 1688
Reputation: 178
I think you should add UserAdmin
into admin.py for Myuser
if you does not add UserAdmin
, password can't be hashed with django:
from django.contrib import admin
from credilet.models import *
from django.contrib.auth.admin import UserAdmin
admin.site.register(MyUser, UserAdmin) # add UserAdmin
Upvotes: 0
Reputation: 3198
If you want to change the authentication system you have to use AbstractBaseUser, look at this full example.
AbstractUser is ok to Extend Django’s default User.
Upvotes: 1