0

I have already ready WEBsite with user authentication. I need to implement corporate accounts functional, so that users of this account can go to the link corporate_account_name.main_domain.com and saw the same site as in main_domain.com only this version especially for them.

How to do it and where to dig? (or at least a list of technologies, frameworks):

  1. One code for all subdomains?
  2. Create separate database for each subdomain? At the same time you need to access data from main_domain to all subdomains and vice versa (subdomain -> main_domain).
  3. It is likely that the code may need to update the long migration of the database data. It is necessary that in this case all the subdomains not froze until the updated one of the bases.
  4. The server on apache. This restart apache every time you create a business account is not possible.
  5. Corporate accounts creates on the web interface main_domain.com (automatically), like a standard user registration. Do not manually!
  6. It is desirable for django.
Danil
  • 11
  • 1
  • 1
    Take a look at this question / answer which I believe will be helpful: http://stackoverflow.com/questions/10738175/pass-subdomain-as-parameter – sberry Oct 25 '16 at 17:44
  • I should mention, you can use the answer I linked to for the general idea. You do not need to pass the subdomain value as a query string parameter. Most likely I would set the value as an environment variable for the request so that it is transparent to the user. – sberry Oct 25 '16 at 17:45
  • 1
    You may be interested in [django-tenant-schemas](https://django-tenant-schemas.readthedocs.io/en/latest/index.html) – devxplorer Oct 25 '16 at 17:47
  • @sberry Thanks for idea. But it is not what I need. I tried it earlier, then I has many problems and questions with separate data and user permissions in backend. I think that is not true approach. – Danil Oct 26 '16 at 10:30
  • @devxplorer It seems to be what I need. Thank you. – Danil Oct 26 '16 at 10:32
  • glad to help, should i create answer? – devxplorer Oct 26 '16 at 10:38
  • @devxplorer Yes. You should ) – Danil Oct 28 '16 at 08:27

1 Answers1

0

There is django-tenant-schemas package, which seems totally fit your needs.

A brief description of how it works (from docs):

Tenants are identified via their host name (i.e tenant.domain.com). This information is stored on a table on the public schema. Whenever a request is made, the host name is used to match a tenant in the database. If there’s a match, the search path is updated to use this tenant’s schema. So from now on all queries will take place at the tenant’s schema. For example, suppose you have a tenant customer at customer.example.com. Any request incoming at customer.example.com will automatically use customer‘s schema and make the tenant available at the request. If no tenant is found, a 404 error is raised. This also means you should have a tenant for your main domain, typically using the public schema.

devxplorer
  • 678
  • 1
  • 4
  • 10