-
Notifications
You must be signed in to change notification settings - Fork 1
/
managers.py
25 lines (20 loc) · 947 Bytes
/
managers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from django.contrib.auth.base_user import BaseUserManager
class PhoneUserManager(BaseUserManager):
use_in_migrations = True
def _create_user(self, username, password, **extra_fields):
"""
Creates and saves a User with the given phone number.
"""
if not username:
raise ValueError('User name not provided')
user = self.model(username=username, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, username, password=None, **extra_fields):
extra_fields.setdefault('is_superuser', False)
return self._create_user(username, password, **extra_fields)
def create_superuser(self, username, password, **extra_fields):
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_staff', True)
return self._create_user(username, password, **extra_fields)