[Fixed]-How to separate users (models) by admins and customers on Django


The way Django offers to you seems to be much more flexible and future-adapted.

  1. You have a built-in User model, which you can override. Anyway, that model has permissions, groups, etc.
  2. If you need different field sets for different kinds of users, you create a OneToOne profile models.
  3. The separation point between your admins (actually, staff users) and regular customers is a User.is_staff attribute.

This way you gain a bunch of cool stuff (compared to two completely different user models):

  • Everything works out of the box: contrib.auth and contrib.admin modules.
  • Easy-customisable separation point: just override the admin_site.has_permission() and here you go.
  • You have the ability (but not obligation) to create users which are either customers and admins.
  • You can assign groups and permissions (different from your admins’ ones) to your customers. Even you don’t need it now, who knows.

As for drawbacks. The only one you’ve pointed out so far: your customers will be having (unused for now) permissions. Well, as they (as well as groups) are just separate tables, your customer data will have no performance of storage overhead.

That is to say, the overhead is negligeable compared to the benefits. I’d strongly recommend staying with Django’s default User model and extending it if necessary.

Leave a comment