2015-06-05 13:33:04 +00:00
|
|
|
from django.contrib.auth.models import AbstractBaseUser, UserManager
|
2015-02-11 13:24:42 +00:00
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
|
|
|
|
class CustomUserNonUniqueUsername(AbstractBaseUser):
|
2015-06-05 13:33:04 +00:00
|
|
|
"""
|
|
|
|
A user with a non-unique username.
|
|
|
|
|
|
|
|
This model is not invalid if it is used with a custom authentication
|
|
|
|
backend which supports non-unique usernames.
|
|
|
|
"""
|
2015-02-11 13:24:42 +00:00
|
|
|
username = models.CharField(max_length=30)
|
2015-06-05 13:33:04 +00:00
|
|
|
email = models.EmailField(blank=True)
|
|
|
|
is_staff = models.BooleanField(default=False)
|
|
|
|
is_superuser = models.BooleanField(default=False)
|
2015-02-11 13:24:42 +00:00
|
|
|
|
|
|
|
USERNAME_FIELD = 'username'
|
2015-06-05 13:33:04 +00:00
|
|
|
REQUIRED_FIELDS = ['email']
|
|
|
|
|
|
|
|
objects = UserManager()
|
2015-02-11 13:24:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CustomUserNonListRequiredFields(AbstractBaseUser):
|
|
|
|
"A user with a non-list REQUIRED_FIELDS"
|
|
|
|
username = models.CharField(max_length=30, unique=True)
|
|
|
|
date_of_birth = models.DateField()
|
|
|
|
|
|
|
|
USERNAME_FIELD = 'username'
|
|
|
|
REQUIRED_FIELDS = 'date_of_birth'
|
|
|
|
|
|
|
|
|
|
|
|
class CustomUserBadRequiredFields(AbstractBaseUser):
|
|
|
|
"A user with a USERNAME_FIELD that appears in REQUIRED_FIELDS (invalid)"
|
|
|
|
username = models.CharField(max_length=30, unique=True)
|
|
|
|
date_of_birth = models.DateField()
|
|
|
|
|
|
|
|
USERNAME_FIELD = 'username'
|
|
|
|
REQUIRED_FIELDS = ['username', 'date_of_birth']
|