I would like to login and manage user with my own class, and not with the one provided by Django.
This is the code to define the user class in my 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]
But when I do django manage.py createsuperuser
it says (after ask me for the email):
TypeError: get_by_natural_key() takes exactly 3 arguments (2 given)
I set AUTH_USER_MODEL = 'MyApp.Client'
in settings.py
I read the documentation but I didn't understand what I have to do. What am I doing wrong?