[Fixed]-Python / Django multi-tenancy solution

13👍

There is a great app called django-tenant-schemas that uses PostgreSQL schemas mechanism to create multi-tenancy.

What you get is specyfing SHARED_APPS that contain objects shared across all the schemas (sub-sites), and TENANT_APPS that contain objects specific for a sub-site, i.e. users, records etc. The schemas are completely isolated from each other.

Each PostgreSQL schema is tied to a domain url, so that middleware checks the HOST part of the request and sets the db connection’s schema to appriopriate one.

In addition, it allows you to define a PUBLIC_SCHEMA_URLCONF which allows you to specify urlconf file for public schema – the meta site that is not tied to any sub-site.

5👍

Sorry for quick and dirty answer, i just share what i’ve done to achieve multi tenancy:

  • django-tenancy I like the author’s approach of using “dynamic model”
  • django-dynamicsite This is where dynamic SITE_ID based on domain will be linked to a tenant

Both libraries above, when combined, is able to serve a django instance which is multi-tenant, and flexible. What i mean flexible here is: you can define any model whether is it “tenant” or “global”. So, you can have a site with global user but per tenant product catalogue, or per tenant + product. From many django app i’ve tried, this is the most flexible way to achieve multi tenancy

👤ayik

3👍

The Django based CMS Mezzanine also has multi-tenancy support.

It has most of the features you requested except the sub-site user controls I think. The admin page can be separated by site for admin users, but the normal users not.

However, if you dont need a CMS this might be an overkill for your use-case, But I wanted to mention it here for completeness.

0👍

I have been trying to use django-tenants for a while along with Wagtail but this combination didn’t work very well, or let me say, despite of a lot of try I was not able to get wagtail admin-page working correctly. I think will try to switch to django-tenant-schemas which I more widely used .

NOTE: django-tenant-schemas is not maintained now.

Leave a comment