Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom user model in django does not allow setting password in admin

I have created a custom user model which I am successfully using within my app.

The problem is that within the Admin, on the user edit screen, I get a display of the present password hash, instead of the very useful interface for setting the password.

I am using Django 1.5b1 on Python 2.7.

How can I convince the Django admin to treat my user model the same way it treats the native User, for the sake of the admin user interface?

like image 751
Krystian Cybulski Avatar asked Dec 01 '12 17:12

Krystian Cybulski


2 Answers

Documentation suggest that you need to register the custom model with admin and also define few methods as well so that admin interface works with custom user model.

You may also have to define built-in forms for User.

From Custom users and django.contrib.admin

You will also need to register your custom User model with the admin. If your custom User model extends AbstractUser, you can use Django's existing UserAdmin class. However, if your User model extends AbstractBaseUser, you'll need to define a custom ModelAdmin class.

like image 100
Rohan Avatar answered Sep 29 '22 01:09

Rohan


Just add this to your form:

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

Borrowed from https://stackoverflow.com/a/15630360/780262

like image 42
Cauê Thenório Avatar answered Sep 29 '22 00:09

Cauê Thenório