python - django extended built in user model not allowing to login in admin -
i using django 1.8 app , using postgresql.i have created super user , can login admin panel after configuring postgresql settings in settings.py file.but after i have decided extend django built in user model , thats why have created new app namely authentication , wrote model
from django.db import models django.contrib.auth.models import abstractbaseuser django.contrib.auth.models import baseusermanager class accountmanager(baseusermanager): def create_user(self, email, password=none, **kwargs): if not email: raise valueerror('users must have valid email address.') if not kwargs.get('username'): raise valueerror('users must have valid username.') account = self.model( email=self.normalize_email(email), username=kwargs.get('username') ) account.set_password(password) account.save() return account def create_superuser(self, email, password, **kwargs): account = self.create_user(email, password, **kwargs) account.is_admin = true account.save() return account class account(abstractbaseuser): email = models.emailfield(unique=true) username = models.charfield(max_length=40, unique=true) first_name = models.charfield(max_length=40, blank=true) last_name = models.charfield(max_length=40, blank=true) tagline = models.charfield(max_length=140, blank=true) is_admin = models.booleanfield(default=false) created_at = models.datetimefield(auto_now_add=true) updated_at = models.datetimefield(auto_now=true) objects = accountmanager() username_field = 'email' required_fields = ['username'] def __unicode__(self): return self.email def get_full_name(self): return ' '.join([self.first_name, self.last_name]) def get_short_name(self): return self.first_name
and have migrated after adding new line in settings.py is
auth_user_model = 'authentication.account'
but after can't able login admin.
to solve this,i have created superuser newly created account model.but problem hasn't been solved.
to test whats going wrong,i have commented out auth_user_model = 'authentication.account' this
#auth_user_model = 'authentication.account'
and allowing me login admin old username , password have set when have configured postgresql , create superuser.
edit after creating superuser account model,i trying login admin, giving newly created email address username , new password,but facing following error
attributeerror @ /admin/login/ 'account' object has no attribute 'is_staff'
to have user model suitable use django admin, need extend abstractuser
- abstract base class implementing featured user model admin-compliant permissions.
https://github.com/django/django/blob/master/django/contrib/auth/models.py#l293
or add additional fields model. @ least need is_active
, is_staff
Comments
Post a Comment