方式一:用自定义的user对象替换django中的默认
在model.py中自定义user对象
'''
自定义用户管理
'''
class MyUserManager(BaseUserManager):
def create_user(self, email, date_of_birth, device_id,password=None):
"""
Creates and saves a User with the given email, date of
birth and password.
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(
email=self.normalize_email(email),
date_of_birth=date_of_birth,
device_id=device_id,
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, date_of_birth, password,device_id):
"""
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(
email,
password=password,
date_of_birth=date_of_birth,
device_id=device_id,
)
user.is_admin = True
user.save(using=self._db)
return user
"""
自定义用户
"""
class MyUser(AbstractBaseUser):
email = models.EmailField(
verbose_name='email address',
max_length=255</