[Answer]-Create User method for Custom Manager Django

1👍

Create the user instance in memory. self.model attribute is populated then you instantiate the model manager in the model class:

class MyUser(AbstractBaseUser):
    objects = UserManager() # here the `objects.model` is set to `MyUser`

Normalized email means that domain part is lower-cased. is_active is True, so user can log in. If any additional fields are passed to create_user() as keyword arguments then assign these fields to the created user.

user = self.model(email=self.normalize_email(email), is_active=True, **kwargs)

Set hashed password.

user.set_password(password)

Save the user instance into the database.

user.save(using=self._db)

Leave a comment