1

According to this answer, if I want to enable the ability to change user passwords in the admin area, I need to add/change some code in UserChangeForm.

I understand this does not mean change the original UserChangeForm, but rather, I should inherit the class which contains the UserChangeForm method, and override the method.

I don't understand where I am supposed to do this. Could someone please give me an example of where/how to override UserChangeForm? Assume I am using a custom user model which inherits AbstractBaseUser.

This is the code (from the linked answer above) for modifying passwords which should go in UserChangeForm:

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>."))

Note I am assuming this will actually display the correct form which will correctly change the password, but it's possible I'm being naive about that.

Thank you.

Community
  • 1
  • 1
Tom Brock
  • 920
  • 7
  • 29

1 Answers1

0

Add your own users app and inherit from django auth user. see my code: This should be your models.py, no need to change any form for this task

  from django.contrib.auth.models import User
  class UserProfile(models.Model):
        user = models.OneToOneField(User)
        # other fields  
        email = models.EmailField(_('email address'), blank=False, null=False,
            unique=True)
        weight = models.IntegerField(default=0,
            validators=[
                MaxValueValidator(9),
                MinValueValidator(0)
            ])
Ohad the Lad
  • 1,889
  • 1
  • 15
  • 24
  • Thanks for your reply. I'm a little confused about it though. This will turn on the ability to change passwords in the admin area for my custom user model? – Tom Brock Sep 27 '16 at 19:00
  • I tried using your code with my user model and it doesn't do anything. Thanks for trying anyway. – Tom Brock Sep 28 '16 at 07:18