Managing multiple user base in same database table

408 views Asked by At

There is a Django project that my team is working on. It will have an administration panel to control several companies under it. To add a new company into the system, the admin will add the domain of the company using the panel. These domains will actually be pointed to our system. We will detect the company by url and manage the views according to that company's domain. For example: We will show the users under that company, do transactions under that company and so on. All information of companies such as user info, company details and members will be stored in our project's main database. Users will log in with their emails. Because of that, we cannot make e-mail field (or username) in database unique by using Django's auth model since email users can register to several different companies without them knowing it. My question is that what should our approach be for this situation?

The question we are looking for answers to:

  • Set a random username to a user, but then we struggle with an issue when creating super user on command line after syncdb because the first parameter will be the one defined with USERNAME_FIELD. How to deal with this unique username field issue?

  • Create different user tables for each company. If so, HOW to do this automatically?

1

There are 1 answers

1
fragles On

Looks like you might run into some complex User / id management scenario. Consider using some sort of single sign on. There are several Django friendly solutions which help you develop an identity broker:

OpenID integration for django.contrib.auth https://launchpad.net/django-openid-auth

I use OpenAm which supports OpenID here is a post which gives some examples Implementing Single Sign On (SSO) using Django

Django Social Auth https://github.com/omab/django-social-auth

Alternatively you can try "Django Authentication using an Email Address" http://www.micahcarrick.com/django-email-authentication.html