python - Custom user model not working on django admin -


i created app authentication, code models is,

from django.contrib.auth.models import abstractbaseuser django.contrib.auth.models import baseusermanager django.db import models  class accountmanager(baseusermanager):     def create_user(self, email, password=none, **kwargs):         if not email:             raise valueerror('users must have valid email address.')          account = self.model(email=self.normalize_email(email))          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)      is_admin = models.booleanfield(default=false)     is_staff = 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 = []      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 

apart changes did added authentication in installed_apps , in settings added auth_user_model = 'authentication.account'

when create super-user shell, working , inserting in db, when try login django admin console, error is_staff not found, added. showing invalid username , password all. tried couple of time generating new 1 each time. doing wrong ?

edit

i adding dbs dump used validate if user created

sqlite> select * authentication_account; 1|pbkdf2_sha256$24000$zrhcxpui3w0g$fh4z9y5vmyaz0feidr908djd3ezw62nm3lpkzxui/es=||me@rahulbhola.in|||1|0|2016-05-28 21:15:59.292988|2016-05-28 21:15:59.415382 

still login in django defaut admin not work

you added is_staff later on seems false default, when migrated field created in database value false in is_staff field.

please make changes below , try

class accountmanager(baseusermanager):     def create_user(self, email, password=none, **kwargs):         if not email:             raise valueerror('users must have valid email address.')          account = self.model(email=self.normalize_email(email))          account.set_password(password)         account.save(using=self.db)          return account      def create_superuser(self, email, password, **kwargs):         account = self.create_user(email, password, **kwargs)         account.is_staff = true         account.is_admin = true         account.save(using=self.db)          return account 

please not account.save(using=self.db) in code above , account.is_staff = true in create admin method. please try creating new user again prefer using shell ( python manage.py shell)

from authentication.models import account

user = account()

user.create_superuser(username='some_username', password='some_password')

user.save()

now user created please try logging in using django admin. should work. had similar issues fixed , able create user , login django admin.

i assuming have created custom authentication backend already, if not please create

hope helps you.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -