Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomUserManager(BaseUserManager):
- def _create_user(self, anonymous, first_name, last_name, email, username, password, home_address, user_type, image_path):
- now = timezone.now()
- if not email:
- raise ValueError('The gives email must be set')
- email = self.normalize_email(email)
- user = self.model(
- anonymous=anonymous,
- first_name=first_name,
- last_name=last_name,
- email=email,
- username=username,
- home_address=home_address,
- user_type=user_type,
- image_path=image_path,
- created_time=now,
- last_login=now
- )
- user.set_password(password)
- user.save(using=self._db)
- return user
- def create_superuser(self, first_name, last_name, email, username, password, home_address, image_path):
- return self._create_user(False, first_name, last_name, email, username, password, home_address, 0, image_path)
- class CustomUser(AbstractBaseUser):
- anonymous = models.BooleanField()
- username = models.CharField(max_length=255, unique=True)
- first_name = models.CharField(max_length=255, blank=True)
- last_name = models.CharField(max_length=255, blank=True)
- email = models.EmailField(blank=True, unique=True)
- home_address = models.CharField(max_length=255, blank=True)
- user_type = models.IntegerField(1)
- image_path = models.CharField(max_length=500, blank=True)
- created_time = models.TimeField()
- USERNAME_FIELD = 'email'
- REQUIRED_FIELDS = ['username', 'home_address', 'first_name', 'last_name', 'user_type']
Add Comment
Please, Sign In to add comment