I'm using a custom User admin by:
class CustomUserAdmin(admin.ModelAdmin):
model = User
...
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
but when I try to change the password via the admin page I get a 404.
user object with primary key u'4/password' does not exist.
Reverting back to the default User admin works fine.
To create a new admin user in Django, we use the createsuperuser command, and this command can be executed using the manage.py utility. Once we execute the given command, it will prompt some fields like Username, Email, Password, Confirm Password.
Username: ola Email address: [email protected] Password: Password (again): Superuser created successfully. Return to your browser.
The default UserAdmin
in django.contrib.auth.admin
implements a lot of functionality, including the change password page.
Your CustomUserAdmin
should subclass UserAdmin
instead of admin.ModelAdmin
, unless you want to reimplement that 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)
Also:
As per the docs, if you inherit from AbstractBaseUser you cannot use the default UserAdmin; or, put another way, you can but only a subset of the functionality will work - changing an existing password might work, but adding a new user will throw exceptions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With