Skip to content Skip to sidebar Skip to footer

Django Custom User Admin Change_password

I'm successfully using a custom user model with django. The last thing to get working is the 'AdminChangePasswordForm' for superusers to change any users password. currently the c

Solution 1:

It seems it's a "bug" in 1.7.x, and fixed in 1.8.x, which set the url name, so you do have to override get_urls():

from django.contrib.auth.admin import UserAdmin as AuthUserAdmin
from django.conf.urls import url


classUserAdmin(AuthUserAdmin):
    defget_urls(self):
        return [
            url(r'^(.+)/password/$', self.admin_site.admin_view(self.user_change_password), name='auth_user_password_change'),
        ] + super(UserAdmin, self).get_urls()

URL:

password_change_url = urlresolvers.reverse('admin:auth_user_password_change', args=(1,))

Solution 2:

So I had similar problem. When I tried to change user password from admin I got url to "/admin/accounts/siteuser/password/" (siteuser is the name of my custom user model) and 404 error with this message: "user object with primary key u'password' does not exist." The investigation showed that the problem was due to bug in django-authtools (1.4.0) as I used NamedUserAdmin class to inherit from.

So the solution is either (if you need to inherit from any custom UserAdmin like NamedUserAdmin from django-authtools):

from django.contrib.auth.forms import UserChangeForm
from authtools.admin import NamedUserAdmin
classSiteUserAdmin(NamedUserAdmin):
    ...
    form = UserChangeForm
    ...

or just inherit from default django UserAdmin:

from django.contrib.auth.admin import UserAdmin
classSiteUserAdmin(UserAdmin):
    pass

Post a Comment for "Django Custom User Admin Change_password"