My custom user model
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager,
PermissionsMixin
# Create your models here.
class mUserManager(BaseUserManager):
def create_user(self, email, username, password = None):
if not email:
raise ValueError("Users must have an email address")
if not username:
raise ValueError("Users must have an username")
user = self.model(
email = self.normalize_email(email),
username = username,
)
user.set_password(password)
user.save()
return user
def create_superuser(self, email, username, password=None):
u = self.create_user(
email = self.normalize_email(email),
username = username,
password=password,
)
u.is_admin = True
u.is_staff = True
u.is_superuser = True
u.is_active = True
u.save()
return u
class mUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(verbose_name="email", max_length=60,
unique=True)
username = models.CharField(max_length=30, unique=True)
date_joined = models.DateTimeField(verbose_name='date joined',
auto_now_add=True)
last_login = models.DateTimeField(verbose_name='last login',
auto_now=True)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
password = models.CharField(max_length=20)
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
objects = mUserManager()
def __str__(self):
return self.email
def has_perm(self, perm, obj=None):
return self.is_admin
def has_module_perms(self, app_label):
return True
And in settings.py, I add this:
AUTH_USER_MODEL = 'accounts.mUser'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.RemoteUserBackend',
'django.contrib.auth.backends.ModelBackend',
)
i run makemigrations ad migrate , then createsuperuser , but i cannot login to admin site. I check the database and find the password seems to have no value (in the database, password is pbkdf2_sha256$216000 , it seems like an empty password, *in the image )