How to remove the password in the users table and User class in a custom user model?
I'm using django-rest-framework token authentication, so i don't need the password field.
Here is my model:
class CustomUserManager(BaseUserManager):
def create_user(phone, name=None):
return User.objects.create(
name=name, phone=phone)
def create_superuser(name, phone=None):
pass
class User(AbstractBaseUser):
"""
Custom django User model.
"""
name = models.CharField(max_length=30,
null=True, validators=[validate_name])
phone = PhoneNumberField(unique=True, blank=False, null=False)
objects = CustomUserManager()
USERNAME_FIELD = 'phone'
REQUIRED_FIELDS = []
Just override the password attribute:
password = None
An alternative to removing the password field would be to use set_unusable_password
, which marks the user as having no password set.
def create_user(phone, name=None):
user = User(name=name, phone=phone)
user.set_unusable_password()
user.save()
return user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With