Monday, August 5, 2013

Re: Using standard Django admin User forms for Custom User model?

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?

https://code.djangoproject.com/ticket/19353
http://stackoverflow.com/a/17496836/139137

Is that something that could be in 1.6?

Cheers,
Victor

On Thursday, 1 August 2013 09:45:51 UTC+10, Russell Keith-Magee wrote:

On Wed, Jul 31, 2013 at 12:36 PM, Victor Hooi <victo...@gmail.com> wrote:
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.

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 %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment