3

I've customized my user model by using AbstractBaseUser.

Everything works fine, but when I am in the Django Admin interface and us the form to change a user's password, in addition to the new password 1 and new password 2 fields, I also see their email in a text box:

image

How can I remove their email address from appearing in my admin change password form? Is there a special Django form that I can subclass?

bones225
  • 1,488
  • 2
  • 13
  • 33

2 Answers2

0

I think you have to customize the password_reset view. Please, read the docs here.

If you want go further, you can override the PasswordResetForm:

from django.contrib.auth.forms import PasswordResetForm

class FooPasswordResetForm(PasswordResetForm):
    ...

Then update your URL and do not forgot to pass your form to the password_reset_form argument:

from django.contrib.auth import views as auth_views
from myapp.forms import FooPasswordResetForm

urlpatterns = [
    ...
    url(
        '^password_reset/',
        auth_views.password_reset,
        {'password_reset_form': FooPasswordResetForm},
    )
]

Please, take also a look at this question My answer is inspired of this question's answer.

Nevenoe
  • 1,032
  • 3
  • 14
  • 37
  • 2
    Thanks for the answer. To clarify I'm talking about in the admin panel so at a url that looks like www.example.com/admin/myapp/user/1/password/ . I already have a password reset view that users can use. – bones225 Aug 01 '19 at 17:45
  • Did u figure out how to solve this @bones225 ? I have a problem similar to this one – gbrennon Aug 24 '20 at 21:41
  • @gbrennon Unfortunately I'm not working on that project anymore -- I don't believe I ever solved it. A couple tips though: 1. Use AbstractUser -- NOT AbstractBaseUser if you haven't already locked in! 2. See what you can do to overwrite the field to make the email read only. – bones225 Aug 25 '20 at 03:05
0

Adding username as a hidden field fixed this for me.

class CustomUserAdmin(UserAdmin):
    readonly_fields = ['username']

I was using the email as a username.

bones225
  • 1,488
  • 2
  • 13
  • 33