summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-07-02 18:10:36 -0400
committerTim Graham <timograham@gmail.com>2018-07-02 18:39:26 -0400
commitf3fa86a89b3b85242f49b2b9acf58b5ea35acc1f (patch)
tree20acfc5f286516cf0c78e66cfd3427ff911678ab /docs
parenteac9ab7ebb1ce0cbbc79c4cf65e8f70b0635a240 (diff)
Fixed #29449 -- Reverted "Fixed #28757 -- Allowed using contrib.auth forms without installing contrib.auth."
This reverts commit 3333d935d2914cd80cf31f4803821ad5c0e2a51d due to a crash if USERNAME_FIELD isn't a CharField.
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/auth/customizing.txt32
-rw-r--r--docs/topics/auth/default.txt9
2 files changed, 24 insertions, 17 deletions
diff --git a/docs/topics/auth/customizing.txt b/docs/topics/auth/customizing.txt
index 67e91b2e54..676aa56d39 100644
--- a/docs/topics/auth/customizing.txt
+++ b/docs/topics/auth/customizing.txt
@@ -814,20 +814,11 @@ are working with.
The following forms are compatible with any subclass of
:class:`~django.contrib.auth.models.AbstractBaseUser`:
-* :class:`~django.contrib.auth.forms.AuthenticationForm`
+* :class:`~django.contrib.auth.forms.AuthenticationForm`: Uses the username
+ field specified by :attr:`~models.CustomUser.USERNAME_FIELD`.
* :class:`~django.contrib.auth.forms.SetPasswordForm`
* :class:`~django.contrib.auth.forms.PasswordChangeForm`
* :class:`~django.contrib.auth.forms.AdminPasswordChangeForm`
-* :class:`~django.contrib.auth.forms.UserCreationForm`
-* :class:`~django.contrib.auth.forms.UserChangeForm`
-
-The forms that handle a username use the username field specified by
-:attr:`~models.CustomUser.USERNAME_FIELD`.
-
-.. versionchanged:: 2.1
-
- In older versions, ``UserCreationForm`` and ``UserChangeForm`` need to be
- rewritten to work with custom user models.
The following forms make assumptions about the user model and can be used as-is
if those assumptions are met:
@@ -838,6 +829,25 @@ if those assumptions are met:
default) that can be used to identify the user and a boolean field named
``is_active`` to prevent password resets for inactive users.
+Finally, the following forms are tied to
+:class:`~django.contrib.auth.models.User` and need to be rewritten or extended
+to work with a custom user model:
+
+* :class:`~django.contrib.auth.forms.UserCreationForm`
+* :class:`~django.contrib.auth.forms.UserChangeForm`
+
+If your custom user model is a simple subclass of ``AbstractUser``, then you
+can extend these forms in this manner::
+
+ from django.contrib.auth.forms import UserCreationForm
+ from myapp.models import CustomUser
+
+ class CustomUserCreationForm(UserCreationForm):
+
+ class Meta(UserCreationForm.Meta):
+ model = CustomUser
+ fields = UserCreationForm.Meta.fields + ('custom_field',)
+
Custom users and :mod:`django.contrib.admin`
--------------------------------------------
diff --git a/docs/topics/auth/default.txt b/docs/topics/auth/default.txt
index 94a8fc592f..4fcd465d89 100644
--- a/docs/topics/auth/default.txt
+++ b/docs/topics/auth/default.txt
@@ -1508,12 +1508,9 @@ provides several built-in forms located in :mod:`django.contrib.auth.forms`:
A :class:`~django.forms.ModelForm` for creating a new user.
- It has three fields: one named after the
- :attr:`~django.contrib.auth.models.CustomUser.USERNAME_FIELD` from the
- user model, and ``password1`` and ``password2``.
-
- It verifies that ``password1`` and ``password2`` match, validates the
- password using
+ It has three fields: ``username`` (from the user model), ``password1``,
+ and ``password2``. It verifies that ``password1`` and ``password2`` match,
+ validates the password using
:func:`~django.contrib.auth.password_validation.validate_password`, and
sets the user's password using
:meth:`~django.contrib.auth.models.User.set_password()`.