Skip to content Skip to sidebar Skip to footer

Django Admin Change User Password

I am new to Django. I have the following code: Model: class MyUser(AbstractUser): profile = models.OneToOneField(Profile, null=True, on_delete=models.PROTECT) My profile model

Solution 1:

The problem was solved by :

classMyAdminPasswordChangeForm(AdminPasswordChangeForm):

    defsave(self, commit=True):
        """
        Saves the new password.
        """
        password = self.cleaned_data["password1"]
        self.user.myuser.set_password(password)
        if commit:
            self.user.myuser.save()
        return self.user.myuser

and

classProfileAdmin(UserAdmin):
    change_password_form = MyAdminPasswordChangeForm

Solution 2:

I ran into this error after upgrading to django 2.x. I had set up my own UserChangeForm, so I just had to update its url:

classEmailUserChangeForm(forms.ModelForm):
    password =ReadOnlyPasswordHashField(label=_("Password"), help_text=_(
        "Raw passwords are not stored, so there is no way to see ""this user's password, but you can change the password "
-        "using <a href=\"password/\">this form</a>."))
+        "using <a href=\"../password/\">this form</a>."))

Post a Comment for "Django Admin Change User Password"