Kaydet (Commit) e8f69609 authored tarafından Tim Graham's avatar Tim Graham

Fixed #19161 - Added missing clean_password method in custom user docs

Thanks DavidW for the report.
üst a386675a
...@@ -408,7 +408,7 @@ installation supports. The first entry in this list (that is, ...@@ -408,7 +408,7 @@ installation supports. The first entry in this list (that is,
``settings.PASSWORD_HASHERS[0]``) will be used to store passwords, and all the ``settings.PASSWORD_HASHERS[0]``) will be used to store passwords, and all the
other entries are valid hashers that can be used to check existing passwords. other entries are valid hashers that can be used to check existing passwords.
This means that if you want to use a different algorithm, you'll need to modify This means that if you want to use a different algorithm, you'll need to modify
:setting:`PASSWORD_HASHERS` to list your prefered algorithm first in the list. :setting:`PASSWORD_HASHERS` to list your preferred algorithm first in the list.
The default for :setting:`PASSWORD_HASHERS` is:: The default for :setting:`PASSWORD_HASHERS` is::
...@@ -2283,13 +2283,19 @@ code would be required in the app's ``admin.py`` file:: ...@@ -2283,13 +2283,19 @@ code would be required in the app's ``admin.py`` file::
class UserChangeForm(forms.ModelForm): class UserChangeForm(forms.ModelForm):
"""A form for updateing users. Includes all the fields on """A form for updateing users. Includes all the fields on
the user, but replaces the password field with admin's the user, but replaces the password field with admin's
pasword hash display field. password hash display field.
""" """
password = ReadOnlyPasswordHashField() password = ReadOnlyPasswordHashField()
class Meta: class Meta:
model = MyUser model = MyUser
def clean_password(self):
# Regardless of what the user provides, return the initial value.
# This is done here, rather than on the field, because the
# field does not have access to the initial value
return self.initial["password"]
class MyUserAdmin(UserAdmin): class MyUserAdmin(UserAdmin):
# The forms to add and change user instances # The forms to add and change user instances
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment