Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserManager(BaseUserManager):
- def create_user(self, phone, password=None):
- if not phone:
- raise ValueError('Please, enter the correct phone number')
- user = self.model(phone=phone)
- user.set_password(password)
- user.save(using=self._db)
- return user
- def create_superuser(self, phone, password):
- user = self.create_user(phone=phone, password=password)
- user.is_admin = True
- user.is_staff = True
- user.is_superuser = True
- user.save(using=self._db)
- return user
- class User(AbstractBaseUser, PermissionsMixin):
- phone_regex = RegexValidator(regex=r'^+?1?d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
- phone = models.CharField(validators=[phone_regex], blank=True, max_length=15)
- phone = models.IntegerField(('contact number'), unique=True, db_index=True)
- # email = models.EmailField(_('email address'), unique=True)
- is_admin = models.BooleanField('superuser', default=False)
- is_staff = models.BooleanField(default=False)
- objects = UserManager()
- USERNAME_FIELD = 'phone'
- def get_full_name(self):
- return str(self.phone)
- def get_short_name(self):
- return str(self.phone)
- def __unicode__(self):
- return str(self.phone)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement