4

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?

David
  • 175
  • 1
  • 5

2 Answers2

2

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/

johnbarr
  • 460
  • 4
  • 6
  • thanks for the links. If I include my department foreign key in REQUIRED_FIELDS of the user model I get the error "return hints['instance']._state.db or DEFAULT_DB_ALIAS AttributeError: 'NoneType' object has no attribute '_state'" when creating the superuser after syncdb. Any ideas, or do I just need to make this field optional? – David Feb 03 '14 at 17:20
  • There is a ticket on this in case anyone else runs into it: [link](https://code.djangoproject.com/ticket/21755) – David Feb 04 '14 at 14:59
1

I also found the following reference helpful: http://www.sofokus.com/blogi/custom-user-model/

David
  • 175
  • 1
  • 5