Django admin is not logged in with user user model

I updated the application that I had on Django 1.4.5 to Django 1.5, and just finished the transition to the user model of the user. When I log in to the application for my application using my own authentication form, with my superuser credentials (generated by running manage.py syncdb ), everything works fine.

I can get authentication, and if I go to /admin , I already registered, as expected. I can navigate perfectly and use the admin panel. However, if I try to login to the admin panel with /admin using the django /admin registration form, I get an error message:

Enter the correct email address and password for the staff account. Note that both fields can be case sensitive.

I did some research and thought this might have something to ModelAdmin with ModelAdmin , so I followed this example from the docs and created a custom ModelAdmin . However, the problem still persists.

Any ideas what could be causing this?

+8
django django-admin
source share
2 answers

Have you added the following lines to your create_superuser function, which is under BaseUserManager ? It might look like this:

 class CustomUserManager(BaseUserManager): def create_user(self, username, email, password=None): if not username: raise ValueError('Dude you need a username.') if not email: raise ValueError( 'type an e-mail..') new_user = self.model( username=username, email=CustomUserManager.normalize_email(email)) new_user.set_password(password) new_user.save(using=self._db) return new_user def create_superuser(self, username, email, password): new = self.create_user( username, email, password=password ) new.is_active = True new.is_staff = True new.is_superuser = True new.save(using=self._db) return new 

In the spotlight:

  new.is_active = True new.is_staff = True new.is_superuser = True 
+4
source share

I had the same problems, but I found @alix's answer so helpful. I forgot to add is_active=True on create_superuser()

 def create_staffuser(self, email, first_name=None, last_name=None, user_role=None, password=None): user = self.create_user( email, first_name=first_name, last_name=last_name, user_role=user_role, password=password, is_staff=True, is_active=True ) return user 

so basically you need to focus on is_active and check your

 # changes the in-build User model to ours (Custom) AUTH_USER_MODEL = 'accounts.User' AUTHENTICATION_BACKENDS = ( # Needed to login by custom User model, regardless of 'allauth' "django.contrib.auth.backends.ModelBackend", # 'allauth' specific authentication methods, such as login by e-mail "allauth.account.auth_backends.AuthenticationBackend", ) 
0
source share

All Articles