1 6
from django.contrib.auth.base_user import BaseUserManager
2

3

4 6
class UserManager(BaseUserManager):
5 6
    use_in_migrations = True
6

7 6
    def _create_user(self, email, password, **extra_fields):
8
        """
9
        Creates and saves a User with the given email and password.
10
        """
11 0
        if not email:
12 0
            raise ValueError('The given email must be set')
13 0
        email = self.normalize_email(email)
14 0
        user = self.model(email=email, **extra_fields)
15 0
        user.set_password(password)
16 0
        user.save(using=self._db)
17 0
        return user
18

19 6
    def create_user(self, email, password=None, **extra_fields):
20 0
        extra_fields.setdefault('is_superuser', False)
21 0
        return self._create_user(email, password, **extra_fields)
22

23 6
    def create_superuser(self, email, password, **extra_fields):
24 0
        extra_fields.setdefault('is_superuser', True)
25

26 0
        if extra_fields.get('is_superuser') is not True:
27 0
            raise ValueError('Superuser must have is_superuser=True.')
28

29 0
        return self._create_user(email, password, **extra_fields)

Read our documentation on viewing source code .

Loading