Using custom admin interrupts changes password form in Django admin

I am using user user admin:

class CustomUserAdmin(admin.ModelAdmin): model = User ... admin.site.unregister(User) admin.site.register(User, CustomUserAdmin) 

but when I try to change the password on the admin page, I get 404.

 user object with primary key u'4/password' does not exist. 

Going back to the user administrator by default works fine.

+6
source share
2 answers

By default, UserAdmin in django.contrib.auth.admin implements many features, including a password change page.

Your CustomUserAdmin should subclass UserAdmin instead of admin.ModelAdmin if you don't want to override this functionality yourself.

 class CustomUserAdmin(UserAdmin): # as an example, this custom user admin orders users by email address ordering = ('email',) admin.site.unregister(User) admin.site.register(User, CustomUserAdmin) 
+16
source

also:

By docs , if you inherit from AbstractBaseUser, you cannot use UserAdmin by default; or, in other words, you can use only part of the functionality - changing an existing password may work, but adding a new user will throw exceptions.

+1
source

Source: https://habr.com/ru/post/901369/


All Articles