Multiplayer company Django

I have a very simple project containing an application with the following models.py:

class UserAccount: user = models.OneToOneField(User) additional = models.CharField(max_length=100) class Project: name = models.CharField(max_length=100) description = models.CharField(max_length=200, blank=True, null=True) class Record: user_account = models.ForeignKey(UserAccount) project = models.ForeignKey(Project) date = models.DateTimeField() 

I want different teams to be able to use this application. However, I want the tables to be separated in some way (don't want all the accounts, projects, and records in the same table).

One solution is to duplicate this application for each team, which is bad. Another is to use something like https://github.com/bcarneiro/django-tenant-schemas , but I want to avoid a few subdomains.

How can I manage the urls:

  • mysite.com/teamA/
  • mysite.com/teamB/
  • mysite.com/admin/teamA/
  • mysite.com/admin/teamB/

I read many articles on the Internet about muti-tenancy in Django, but I did not find a single solution that would suit my needs:

  • 1 DB, but not all tenant data in the same tables
  • Do not use sites or subdomains, but instead: mysite.com/tenant1/, mysite.com/tenant2/,

Thank you for your help!

+4
source share
1 answer

It should not be too complicated. You will need to write your own middleware and put it in your settings.py file. Copy and paste this file and modify it to use a different part of your URL than the subdomain here:

https://github.com/bcarneiro/django-tenant-schemas/blob/master/tenant_schemas/middleware.py

+1
source

Source: https://habr.com/ru/post/1484395/


All Articles