当我为自定义用户模型创建超级用户时,它不向我提供用户名、名字、姓氏,然后显示此错误:MyAccountManager.create_superuser() 缺少 3 个必需的位置参数:'first_name'、'last_name' 和 'username'
这是我的代码:
class MyAccountManager(BaseUserManager):
def create_user(self,first_name,last_name, username, email, password=None):
email = self.normalize_email(email)
if email is None:
raise ValueError('User Must have a email')
first_name = first_name.title()
last_name = last_name.title()
username = username.title()
user = self.model(
email=email,
first_name= first_name,
last_name=last_name,
username=username
)
user.set_password(password)
user.save(using = self._db)
return user
def create_superuser(self, email,first_name,last_name, username, password=None):
user = self.create_user(email=email, password=password,first_name= first_name,
last_name=last_name,
username=username),
user.is_staff = True
user.save(using = self._db)
class Account(AbstractBaseUser):
first_name = models.CharField(max_length=50, blank=True, null=True)
last_name = models.CharField(max_length=50, blank=True, null=True)
username = models.CharField(
max_length=50, default='test', unique=True, blank=True, null=True)
email = models.EmailField(max_length=100, unique=True)
phone_number = models.CharField(max_length=50)
# required
date_joined = models.DateTimeField(auto_now_add=True)
last_login = models.DateTimeField(auto_now_add=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
objects = MyAccountManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELD = ['username', 'first_name','last_name']