Using standard Django admin User forms for Custom User model?

798 views
Skip to first unread message

Victor Hooi

unread,
Jul 31, 2013, 12:36:16 AM7/31/13
to django...@googlegroups.com
Hi,

When you add a Django User through the admin, it presents you with a initial screen to enter a username and password  (/admin/auth/user/add/), and then handles hashing for you.

Also, when you go to edit a User, it gives you a Change Password form (e.g. /admin/auth/user/2/password/)

I'm using a custom user model in my Django app, by inheriting from AbstractCustomer.

If I add this to the admin now, password is just a standard textbox, and obviously if I create a user through that, I can't login since I assume it's not hashing the password.

Is there any way I can use the normal Django User admin forms with a custom User model?

Secondly, I tried creating a user via the create_user() method on my custom User object - I still wasn't able to login to the admin using that username/password, which I thought was weird.

Cheers,
Victor

Russell Keith-Magee

unread,
Jul 31, 2013, 7:45:51 PM7/31/13
to django...@googlegroups.com
Have you read the documentation on this issue? 


The docs discuss what you have to do in order to get your User model represented in the admin, and also provide a worked example.

If you've got a specific question that isn't covered by the docs, or if you're confused by what the docs say, let us know.

Yours,
Russ Magee %-)

Victor Hooi

unread,
Aug 5, 2013, 5:21:44 AM8/5/13
to django...@googlegroups.com
Hi,

I got it working at a basic level by just registering against UserAdmin.

from django.contrib.auth.admin import UserAdmin
admin.site.register(Customer, UserAdmin)

For custom fields, I just needed to add them to fieldsets.

However, even though I could view/edit users, adding new Users failed - the forms seemed to be looking specifically for auth_user.

Apparently this is something that could be made easier?


Is that something that could be in 1.6?

Cheers,
Victor
Reply all
Reply to author
Forward
0 new messages