python-create_superuser()获得了意外的关键字参数”
作者:互联网
我正在尝试创建用于身份验证的自定义用户模型,但是我看不到代码中的错误,也许您可以看到并为我提供帮助.
相信我,我在发布之前会在整个论坛中进行搜索,即使是I read this post,但这也是关于哈希密码的问题
当我尝试使用命令在shell中创建超级用户时
c:\employee>python manage.py createsuperuser
我收到以下错误(底部的完整回溯)
create_superuser() got an unexpected keyword argument 'NickName'
这是我的seetings.py
#seetings.py
AUTH_USER_MODEL = 'Sinergia.Employee'
和我的models.py
#models.py
# -*- coding: utf-8 -*-
from django.db import models
# Importando la configuración
from django.conf import settings
# Importando clases para los administradores
# de usuario.
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
class EmployeeManager(BaseUserManager):
def create_user(self, email, nickname, password = None):
if not email:
raise ValueError('must have an email address.')
usuario = self.model\
(
Email = self.normalize_email(email),
NickName = nickname,
)
usuario.set_password(password)
usuario.save(using = self._db)
return usuario
def create_superuser(self, email, nickname, password):
usuario = self.create_user\
(
email = email,
nickname = nickname,
password = password,
)
usuario.is_admin = True
usuario.save(using = self._db)
return usuario
class Employee(AbstractBaseUser):
Email = models.EmailField(max_length = 254, unique = True)
NickName = models.CharField(max_length = 40, unique = True)
FBAccount = models.CharField(max_length = 300)
# Estados del Usuario.
is_active = models.BooleanField(default = True)
is_admin = models.BooleanField(default = False)
object = EmployeeManager()
# Identificador Único del Usuario.
USERNAME_FIELD = 'Email'
# Campos obligatorios.
REQUIRED_FIELDS = ['NickName']
def get_full_name(self):
return self.Email
def get_short_name(self):
return self.NickName
def __unicode__(self):
return self.Email
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
@property
def is_staff(self):
"Is the user a member of staff?"
# Simplest possible answer: All admins are staff
return self.is_admin
class Article(models.Model):
Author = models.ForeignKey(settings.AUTH_USER_MODEL)
解决方法:
分配管理员时,您遇到错字:
class Employee(AbstractBaseUser):
...
objects = EmployeeManager()
对象,而不是对象.
标签:root,python,django,django-models 来源: https://codeday.me/bug/20191121/2052741.html