Search code examples
djangodjango-modelsdjango-authenticationdjango-custom-user

Extend Django user model with custom fields, receivers and backend


I am designing a Django application (v1.6) and need to do several things with users:

  1. Add custom fields, such as a foreign key for user department
  2. Trigger database changes when certain fields change. For example, when the user's department changes I need to move inventory in another model out of the old department and into the new. I was planning to use a pre_save receiver to do this.
  3. Define custom permissions, such as a user can only modify rows in a table that are associated with their department.
  4. Eventually I want to integrate the application with our Active Directory server for authentication.

I looked at the options in the documentation and see that there are several options, from extending the user model with a one-to-one relationship to writing a custom user model.

What design should I use to meet all of the above goals?


Solution

  • Take a look at this blog post: it provides all the design principles to achieve your goals. http://www.roguelynn.com/words/django-custom-user-models/

    I would also take a look here for more information about Configurable User Models, if you want to have your own authentication scheme: http://procrastinatingdev.com/django/using-configurable-user-models-in-django-1-5/