Fixed #28089 -- Removed requirement to implement get_short_name() and get_full_name() in AbstractBaseUser subclasses.
This commit is contained in:
parent
e86f4786a7
commit
5df0ff4155
|
@ -119,12 +119,6 @@ class AbstractBaseUser(models.Model):
|
||||||
def has_usable_password(self):
|
def has_usable_password(self):
|
||||||
return is_password_usable(self.password)
|
return is_password_usable(self.password)
|
||||||
|
|
||||||
def get_full_name(self):
|
|
||||||
raise NotImplementedError('subclasses of AbstractBaseUser must provide a get_full_name() method')
|
|
||||||
|
|
||||||
def get_short_name(self):
|
|
||||||
raise NotImplementedError('subclasses of AbstractBaseUser must provide a get_short_name() method.')
|
|
||||||
|
|
||||||
def get_session_auth_hash(self):
|
def get_session_auth_hash(self):
|
||||||
"""
|
"""
|
||||||
Return an HMAC of the password field.
|
Return an HMAC of the password field.
|
||||||
|
|
|
@ -319,6 +319,13 @@ Miscellaneous
|
||||||
|
|
||||||
an input of ``"1.345"`` is now converted to ``1345`` instead of ``1.345``.
|
an input of ``"1.345"`` is now converted to ``1345`` instead of ``1.345``.
|
||||||
|
|
||||||
|
* Subclasses of :class:`~django.contrib.auth.models.AbstractBaseUser` are no
|
||||||
|
longer required to implement ``get_short_name()`` and ``get_full_name()``.
|
||||||
|
(The base implementations that raise ``NotImplementedError`` are removed.)
|
||||||
|
``django.contrib.admin`` uses these methods if implemented but doesn't
|
||||||
|
require them. Third-party apps that use these methods may want to adopt a
|
||||||
|
similar approach.
|
||||||
|
|
||||||
.. _deprecated-features-2.0:
|
.. _deprecated-features-2.0:
|
||||||
|
|
||||||
Features deprecated in 2.0
|
Features deprecated in 2.0
|
||||||
|
|
|
@ -536,18 +536,11 @@ Specifying a custom user model
|
||||||
|
|
||||||
Django expects your custom user model to meet some minimum requirements.
|
Django expects your custom user model to meet some minimum requirements.
|
||||||
|
|
||||||
#. If you use the default authentication backend, then your model must have a
|
If you use the default authentication backend, then your model must have a
|
||||||
single unique field that can be used for identification purposes. This can
|
single unique field that can be used for identification purposes. This can
|
||||||
be a username, an email address, or any other unique attribute. A non-unique
|
be a username, an email address, or any other unique attribute. A non-unique
|
||||||
username field is allowed if you use a custom authentication backend that
|
username field is allowed if you use a custom authentication backend that
|
||||||
can support it.
|
can support it.
|
||||||
|
|
||||||
#. Your model must provide a way to address the user in a "short" and
|
|
||||||
"long" form. The most common interpretation of this would be to use
|
|
||||||
the user's given name as the "short" identifier, and the user's full
|
|
||||||
name as the "long" identifier. However, there are no constraints on
|
|
||||||
what these two methods return - if you want, they can return exactly
|
|
||||||
the same value.
|
|
||||||
|
|
||||||
The easiest way to construct a compliant custom user model is to inherit from
|
The easiest way to construct a compliant custom user model is to inherit from
|
||||||
:class:`~django.contrib.auth.models.AbstractBaseUser`.
|
:class:`~django.contrib.auth.models.AbstractBaseUser`.
|
||||||
|
@ -636,16 +629,21 @@ password resets. You must then provide some key implementation details:
|
||||||
|
|
||||||
.. method:: get_full_name()
|
.. method:: get_full_name()
|
||||||
|
|
||||||
A longer formal identifier for the user. A common interpretation
|
Optional. A longer formal identifier for the user such as their full
|
||||||
would be the full name of the user, but it can be any string that
|
name. If implemented, this appears alongside the username in an
|
||||||
identifies the user.
|
object's history in :mod:`django.contrib.admin`.
|
||||||
|
|
||||||
.. method:: get_short_name()
|
.. method:: get_short_name()
|
||||||
|
|
||||||
A short, informal identifier for the user. A common interpretation
|
Optional. A short, informal identifier for the user such as their
|
||||||
would be the first name of the user, but it can be any string that
|
first name. If implemented, this replaces the username in the greeting
|
||||||
identifies the user in an informal way. It may also return the same
|
to the user in the header of :mod:`django.contrib.admin`.
|
||||||
value as :meth:`django.contrib.auth.models.User.get_full_name()`.
|
|
||||||
|
.. versionchanged:: 2.0
|
||||||
|
|
||||||
|
In older versions, subclasses are required to implement
|
||||||
|
``get_short_name()`` and ``get_full_name()`` as ``AbstractBaseUser``
|
||||||
|
has implementations that raise ``NotImplementedError``.
|
||||||
|
|
||||||
.. admonition:: Importing ``AbstractBaseUser``
|
.. admonition:: Importing ``AbstractBaseUser``
|
||||||
|
|
||||||
|
@ -1060,14 +1058,6 @@ authentication app::
|
||||||
USERNAME_FIELD = 'email'
|
USERNAME_FIELD = 'email'
|
||||||
REQUIRED_FIELDS = ['date_of_birth']
|
REQUIRED_FIELDS = ['date_of_birth']
|
||||||
|
|
||||||
def get_full_name(self):
|
|
||||||
# The user is identified by their email address
|
|
||||||
return self.email
|
|
||||||
|
|
||||||
def get_short_name(self):
|
|
||||||
# The user is identified by their email address
|
|
||||||
return self.email
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.email
|
return self.email
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,5 @@ with RemoveGroupsAndPermissions():
|
||||||
USERNAME_FIELD = 'email'
|
USERNAME_FIELD = 'email'
|
||||||
REQUIRED_FIELDS = ['date_of_birth']
|
REQUIRED_FIELDS = ['date_of_birth']
|
||||||
|
|
||||||
def get_full_name(self):
|
|
||||||
return self.email
|
|
||||||
|
|
||||||
def get_short_name(self):
|
|
||||||
return self.email
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.email
|
return self.email
|
||||||
|
|
|
@ -43,12 +43,6 @@ class CustomUser(AbstractBaseUser):
|
||||||
USERNAME_FIELD = 'email'
|
USERNAME_FIELD = 'email'
|
||||||
REQUIRED_FIELDS = ['date_of_birth']
|
REQUIRED_FIELDS = ['date_of_birth']
|
||||||
|
|
||||||
def get_full_name(self):
|
|
||||||
return self.email
|
|
||||||
|
|
||||||
def get_short_name(self):
|
|
||||||
return self.email
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.email
|
return self.email
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue