0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Cleanup and documentation of AbstractUser base class.

This commit is contained in:
Russell Keith-Magee 2012-09-16 15:11:10 +08:00
parent a9491a8776
commit abcb027190
2 changed files with 23 additions and 5 deletions

View File

@ -228,10 +228,11 @@ def _user_has_module_perms(user, app_label):
class AbstractBaseUser(models.Model): class AbstractBaseUser(models.Model):
REQUIRED_FIELDS = []
password = models.CharField(_('password'), max_length=128) password = models.CharField(_('password'), max_length=128)
last_login = models.DateTimeField(_('last login'), default=timezone.now) last_login = models.DateTimeField(_('last login'), default=timezone.now)
REQUIRED_FIELDS = []
class Meta: class Meta:
abstract = True abstract = True
@ -279,12 +280,11 @@ class AbstractBaseUser(models.Model):
@python_2_unicode_compatible @python_2_unicode_compatible
class AbstractUser(AbstractBaseUser): class AbstractUser(AbstractBaseUser):
""" """
Users within the Django authentication system are represented by this An abstract base class implementing a fully featured User model with
model. admin-compliant permissions.
Username and password are required. Other fields are optional. Username, password and email are required. Other fields are optional.
""" """
REQUIRED_FIELDS = ['email']
username = models.CharField(_('username'), max_length=30, unique=True, username = models.CharField(_('username'), max_length=30, unique=True,
help_text=_('Required. 30 characters or fewer. Letters, numbers and ' help_text=_('Required. 30 characters or fewer. Letters, numbers and '
'@/./+/-/_ characters'), '@/./+/-/_ characters'),
@ -314,6 +314,8 @@ class AbstractUser(AbstractBaseUser):
objects = UserManager() objects = UserManager()
REQUIRED_FIELDS = ['email']
class Meta: class Meta:
verbose_name = _('user') verbose_name = _('user')
verbose_name_plural = _('users') verbose_name_plural = _('users')
@ -434,10 +436,18 @@ class AbstractUser(AbstractBaseUser):
raise SiteProfileNotAvailable raise SiteProfileNotAvailable
return self._profile_cache return self._profile_cache
class User(AbstractUser): class User(AbstractUser):
"""
Users within the Django authentication system are represented by this
model.
Username, password and email are required. Other fields are optional.
"""
class Meta: class Meta:
swappable = 'AUTH_USER_MODEL' swappable = 'AUTH_USER_MODEL'
@python_2_unicode_compatible @python_2_unicode_compatible
class AnonymousUser(object): class AnonymousUser(object):
id = None id = None

View File

@ -1918,6 +1918,14 @@ additional methods:
Unlike `create_user()`, `create_superuser()` *must* require the caller Unlike `create_user()`, `create_superuser()` *must* require the caller
to provider a password. to provider a password.
Extending Django's default User
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you're entirely happy with Django's :class:`~django.contrib.auth.models.User`
model and you just want to add some additional profile information, you can
simply subclass :class:`~django.contrib.auth.models.AbstractUser` and add your
custom profile fields.
Custom users and django.contrib.admin Custom users and django.contrib.admin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~