Guest User

Untitled

a guest
Nov 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. class CustomUserManager(BaseUserManager):
  2. def _create_user(self, anonymous, first_name, last_name, email, username, password, home_address, user_type, image_path):
  3. now = timezone.now()
  4.  
  5. if not email:
  6. raise ValueError('The gives email must be set')
  7.  
  8. email = self.normalize_email(email)
  9. user = self.model(
  10. anonymous=anonymous,
  11. first_name=first_name,
  12. last_name=last_name,
  13. email=email,
  14. username=username,
  15. home_address=home_address,
  16. user_type=user_type,
  17. image_path=image_path,
  18. created_time=now,
  19. last_login=now
  20. )
  21.  
  22. user.set_password(password)
  23. user.save(using=self._db)
  24. return user
  25.  
  26.  
  27. def create_superuser(self, first_name, last_name, email, username, password, home_address, image_path):
  28. return self._create_user(False, first_name, last_name, email, username, password, home_address, 0, image_path)
  29.  
  30. class CustomUser(AbstractBaseUser):
  31. anonymous = models.BooleanField()
  32. username = models.CharField(max_length=255, unique=True)
  33. first_name = models.CharField(max_length=255, blank=True)
  34. last_name = models.CharField(max_length=255, blank=True)
  35. email = models.EmailField(blank=True, unique=True)
  36. home_address = models.CharField(max_length=255, blank=True)
  37. user_type = models.IntegerField(1)
  38. image_path = models.CharField(max_length=500, blank=True)
  39. created_time = models.TimeField()
  40.  
  41. USERNAME_FIELD = 'email'
  42. REQUIRED_FIELDS = ['username', 'home_address', 'first_name', 'last_name', 'user_type']
Add Comment
Please, Sign In to add comment