Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. class UserManager(BaseUserManager):
  2. def create_user(self, phone, password=None):
  3. if not phone:
  4. raise ValueError('Please, enter the correct phone number')
  5.  
  6. user = self.model(phone=phone)
  7. user.set_password(password)
  8. user.save(using=self._db)
  9. return user
  10.  
  11. def create_superuser(self, phone, password):
  12. user = self.create_user(phone=phone, password=password)
  13. user.is_admin = True
  14. user.is_staff = True
  15. user.is_superuser = True
  16. user.save(using=self._db)
  17. return user
  18.  
  19.  
  20. class User(AbstractBaseUser, PermissionsMixin):
  21. phone_regex = RegexValidator(regex=r'^+?1?d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
  22. phone = models.CharField(validators=[phone_regex], blank=True, max_length=15)
  23. phone = models.IntegerField(('contact number'), unique=True, db_index=True)
  24. # email = models.EmailField(_('email address'), unique=True)
  25. is_admin = models.BooleanField('superuser', default=False)
  26. is_staff = models.BooleanField(default=False)
  27.  
  28. objects = UserManager()
  29.  
  30. USERNAME_FIELD = 'phone'
  31.  
  32. def get_full_name(self):
  33. return str(self.phone)
  34.  
  35. def get_short_name(self):
  36. return str(self.phone)
  37.  
  38. def __unicode__(self):
  39. return str(self.phone)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement