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.
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
- How do I override help_text in django's admin interface
- Enforce at least one value in a many-to-many relation, in Django?
- How do I simulate connection errors and request timeouts in python unit tests
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.
- Python/Tornado – compressing static files
- Django Allauth Custom Login Does Not Show Errors
- GeoDjango can't find gdal on docker python alpine based image
- How can I sort by the id of a ManyToManyField in Django?
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.