mirror of
https://github.com/django/django.git
synced 2024-11-20 08:24:58 +00:00
1ea87c8c79
Clarified docs to say that a non-unique USERNAME_FIELD is permissable as long as the custom auth backend can support it.
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from django.contrib.auth.models import AbstractBaseUser, UserManager
|
|
from django.db import models
|
|
|
|
|
|
class CustomUserNonUniqueUsername(AbstractBaseUser):
|
|
"""
|
|
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.
|
|
"""
|
|
username = models.CharField(max_length=30)
|
|
email = models.EmailField(blank=True)
|
|
is_staff = models.BooleanField(default=False)
|
|
is_superuser = models.BooleanField(default=False)
|
|
|
|
USERNAME_FIELD = 'username'
|
|
REQUIRED_FIELDS = ['email']
|
|
|
|
objects = UserManager()
|
|
|
|
class Meta:
|
|
app_label = 'auth'
|
|
|
|
|
|
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 Meta:
|
|
app_label = 'auth'
|
|
|
|
|
|
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']
|
|
|
|
class Meta:
|
|
app_label = 'auth'
|