我想使用自己的类登录和管理用户,而不是使用Django提供的用户。
这是在module.py
中定义用户类的代码:
class ClientManager(models.Manager):
def create_superuser(self, email, password, first_name, last_name):
users = get_user_model()
users.objects.create_superuser(email, password, first_name, last_name)
def get_by_natural_key(self, first_name, last_name):
return self.get(first_name=first_name, last_name=last_name)
class Client(models.Model, UserManager):
REQUIRED_FIELDS = ('first_name', 'last_name', 'password',)
USERNAME_FIELD = 'email'
first_name = models.TextField(max_length=250)
last_name = models.TextField(max_length=250)
email = models.TextField(max_length=250, unique=True)
password = models.TextField(max_length=250)
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
objects = ClientManager()
def __unicode__(self):
return '%s %s' % (self.first_name, self.last_name)
def get_natural_key(self):
return [self.first_name, self.last_name]
但当我django manage.py createsuperuser
时,它(在询问我的电子邮件后):
TypeError: get_by_natural_key() takes exactly 3 arguments (2 given)
我在AUTH_USER_MODEL = 'MyApp.Client'
settings.py
我阅读了文档,但我不明白自己要做什么。我做错了什么?