Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserManager(BaseUserManager):
- def create_user(self, email, password=None, **extra_fields):
- """Creates and saves a new user"""
- if not email:
- raise ValueError("Users must have an email address")
- user = self.model(email=self.normalize_email(email), **extra_fields)
- user.set_password(password)
- user.save(using=self._db) # required for supporting multiple databases
- return user
- def create_superuser(self, email, password):
- """Creates and saves a new superuser"""
- user = self.create_user(email, password)
- user.is_staff = True
- user.is_superuser = True
- user.save(using=self._db)
- return user
- class User(AbstractBaseUser, PermissionsMixin):
- """Custom user model that supports using email instead of username"""
- email = models.EmailField(max_length=255, unique=True)
- first_name = models.CharField(max_length=255)
- last_name = models.CharField(max_length=255)
- is_active = models.BooleanField(default=True)
- is_staff = models.BooleanField(default=False)
- objects = UserManager()
- USERNAME_FIELD = "email"
- @property
- def full_name(self):
- return f'{self.first_name} {self.last_name}'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement