Thursday, May 29, 2014

Re: How to create a custom user model ?

Ah.
AbstractUser (AU) inherits from AbstractBaseUser (ABU).
ABU only provides password and last login fields. You should use it as your base class if you want to do something radically different from the  django user. The best example would be using email addresse for the username field.A standard Django User model is just a wrapper around the AU model. If you are happy with what the standard user is (Username, first, last, email, is_staff, is_admin, date joined, and the abstract base user fields) but want to add a few new fields, like in your case company_name.

For your questions:
1. you are correct that you need to register the custom user to the admin. You will also have to write an admin class as shown in the example. You will do it by admin.site.register(CustomUser, CustomUserAdmin)
2. Also correct. Just take the default forms and add the company_name field to them. Also just follow the example I linked to

Hope this helps some,
Kirby

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f89b0570-139f-4ddd-8ce7-9198b64dfc91%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment