from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
# Create your models here.
class MyAccountManager(BaseUserManager):
def create_user(self, email, username, password=None):
if not email:
raise ValueError('user must have smartcard')
if not username:
raise ValueError('must have username')
user = self.create_user(
email=self.normalize_email(email),
username=username,
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, username, password):
user = self.create_user(
email=self.normalize_email(email),
password=password,
username=username,
)
user.is_admin =True
user.is_staff =True
user.is_superuser=True
user.save(using=self._db)
return user
class Account(AbstractBaseUser):
username = models.CharField(max_length=100, unique=True)
email = models.EmailField(verbose_name="email", max_length=30, unique=True)
department = models.CharField(max_length=30, choices=DEPARTMENT)
USERNAME_FIELD = 'email'
REQUIRED_FIELD = ['username',]
objects=MyAccountManager()
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
I just can't get what is wrong.
While creating a superuser the prompt doesnt ask me for entering username
I modified the settings.py file as well. Tried several times with various databases. I have also added the username in REQUIRED_FIELDS section.