2

In a Django 1.5 project, I've created a custom User model extending from AbstractBaseUser to make the email address the primary key (instead of a username).

How do I get the change password functionality for UserAdmin in the django admin interface? I tried extending UserAdmin with a class called CustomUserAdmin (much like the answer suggested in Using custom User admin breaks change password form in Django's admin), but I get the following error message

CustomUserAdmin.list_display[0], 'username' is not a callable or an attribute of 'CustomUserAdmin' or found in the model 'User'.

I basically want the default admin interface except the password field (which I want from UserAdmin).

How do I do this?

1 Answer 1

0

Looks like your custom User model doesn't have 'username' field. And since CustomUserAdmin is extending UserAdmin, which assumes 'username' field is present; we are getting this error.

I would suggest you add a 'username' field in your custom model and store the same value of 'email' field in it.

Or override all the attributes of UserAdmin class which uses 'username'. Eg:

class CustomUserAdmin(UserAdmin):
    list_display = ['email', 'first_name'.....]
Sign up to request clarification or add additional context in comments.

2 Comments

i would rather not have a hacky solution that has to (1) get rid of the username assumption in UserAdmin or (2) fake a username field. A big reason why I went through the trouble of extending AbstractBaseUser over BaseUser was because I didn't want to deal with an extraneous username field
@fangsterr UserAdmin class is based on django auth User model. Now we have a custom User model, which is quite different from auth User; but we want CustomUserAdmin to subclass UserAdmin. The only way to achieve this is to override the attributes/functions of UserAdmin to suit our structure. If you don't want to do this, then CustomUserAdmin should reimplement that functionality.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.