Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyUser(AbstractBaseUser, PermissionsMixin):
- USER_ACCOUNT_TYPE_CHOICES = (
- (1, _('organization')),
- (2, _('personal')),
- )
- user_account_type = models.IntegerField(_('account type'), choices=USER_ACCOUNT_TYPE_CHOICES)
- email = models.EmailField(_('email address'), max_length=255, unique=True)
- class MyUserManager(BaseUserManager):
- def _create_user(self, email, password, username=None, **extra_fields):
- """
- Creates and saves a User with the given username, email and password.
- """
- if not email:
- raise ValueError('The given email must be set')
- email = self.normalize_email(email)
- if username:
- username = self.model.normalize_username(username)
- user = self.model(username=username, email=email, **extra_fields)
- else:
- user = self.model(email=email, **extra_fields)
- user.set_password(password)
- user.save(using=self._db)
- return user
- def create_user(self, email=None, password=None, username=None, **extra_fields):
- extra_fields.setdefault('is_staff', False)
- extra_fields.setdefault('is_superuser', False)
- return self._create_user(email, password, username=username, **extra_fields)
- def create_superuser(self, email, password, username=None, **extra_fields):
- extra_fields.setdefault('is_staff', True)
- extra_fields.setdefault('is_superuser', True)
- if extra_fields.get('is_staff') is not True:
- raise ValueError('Superuser must have is_staff=True.')
- if extra_fields.get('is_superuser') is not True:
- raise ValueError('Superuser must have is_superuser=True.')
- return self._create_user(email, password, username=username, **extra_fields)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement