2

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

saurabh
  • 293
  • 2
  • 7
  • 19

2 Answers2

1

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.

grigno
  • 3,128
  • 4
  • 35
  • 47
  • i just want to use email as my username but by extending it through abstract base user I have to go through all the backend system I mean I have to define my custom create_user and create_superuser and all that stuff and for avoiding that I used Abstract user so is there any possibility that I could use abstract user and and just define my username and rest of the things just same as django's user object – saurabh Feb 10 '14 at 09:57
0

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
omides248
  • 128
  • 2
  • 12