How to intercept password change in admin module ?

38 views
Skip to first unread message

Marc

unread,
Dec 1, 2011, 3:12:59 AM12/1/11
to Django users
Hello,

I reformulate my previous question having not no answer.

I would like to get control on the password change form of the admin
site (let us say record some trace in another table).

I put the following code in the admin.py:

class MyUserAdmin(UserAdmin):
def save_model(self, request, obj, form, change):
...
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

The problem is that when user calls the password change built-in form
the
save_model method is not called.

Is there a way to intercept the password change action ?

Thanks

Reinout van Rees

unread,
Dec 1, 2011, 5:31:25 AM12/1/11
to django...@googlegroups.com
On 01-12-11 09:12, Marc wrote:
> Hello,
>
> I reformulate my previous question having not no answer.
>
> I would like to get control on the password change form of the admin
> site (let us say record some trace in another table).
>
> I put the following code in the admin.py:
>
> class MyUserAdmin(UserAdmin):
> def save_model(self, request, obj, form, change):
> ...
> admin.site.unregister(User)
> admin.site.register(User, MyUserAdmin)
>
> The problem is that when user calls the password change built-in form
> the
> save_model method is not called.

Just a guess: is your application higher up in the INSTALLED_APPS list
than Django's build-in apps?

Reinout

--
Reinout van Rees http://reinout.vanrees.org/
rei...@vanrees.org http://www.nelen-schuurmans.nl/
"If you're not sure what to do, make something. -- Paul Graham"

Marc

unread,
Dec 1, 2011, 9:00:21 AM12/1/11
to Django users
Thanks for your suggestion. Yes it is. Save_model is called when I
modify the User but not when I change the password using the dedicated
form.

Martin J. Laubach

unread,
Dec 1, 2011, 9:53:45 AM12/1/11
to django...@googlegroups.com
How about just listening to pre_save or post_save signals on the User model? 

       mjl

Reply all
Reply to author
Forward
0 new messages