Guest User

Untitled

a guest
Sep 19th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. class UserManager(BaseUserManager):
  2.     use_in_migrations = True
  3.  
  4.     def _create_user(self, email, password, **extra_fields):
  5.         """
  6.        Creates and saves a User with the given email and password.
  7.        """
  8.         if not email:
  9.             raise ValueError('The given email must be set')
  10.         email = self.normalize_email(email)
  11.         user = self.model(email=email, **extra_fields)
  12.         user.set_password(password)
  13.         user.save(using=self._db)
  14.         return user
  15.  
  16.     def create_user(self, email, password=None, **extra_fields):
  17.         extra_fields.setdefault('is_superuser', False)
  18.         return self._create_user(email, password, **extra_fields)
  19.  
  20.     def create_superuser(self, email, password, **extra_fields):
  21.         extra_fields.setdefault('is_superuser', True)
  22.  
  23.         if extra_fields.get('is_superuser') is not True:
  24.             raise ValueError('Superuser must have is_superuser=True.')
  25.  
  26.         return self._create_user(email, password, **extra_fields)
Add Comment
Please, Sign In to add comment