Django-tenants basics: SHARED_APPS vs TENANT_APPS
I am using django-tenants for a multi-tenant app.
In the docs it talks about setting up SHARED_APPS
and TENANT_APPS
.
SHARED_APPS is a tuple of strings just like INSTALLED_APPS and should contain all apps that you want to be synced to public
If I want an app (e.g. django.contrib.auth
) to be accessible on both the public schema and shared schema, do I include it only in the SHARED_APPS
or do I need to include it in both SHARED_APPS
and TENANT_APPS
?
"SHARED" would imply that everything in this list is accessible via all tenants and the public schema, but the docs seem to imply otherwise?
When using django-tenants, your database will contain a public
schema (ie. directory), and a schema for each tenant, say tenant1
, tenant2
, ..
The data of models belonging to a SHARED_APPS
will end up in the public folder, and will be accessible by all other tenants (schema's). Hence, it is sufficient to only include int once in the SHARED_APPS
I am the maintainer of Django Tenants. If you want the same user to be able to access in both shared and tenant you would put it in just SHARED_APPS. However this would mean that the same user would be able to get in to multiple tenants I wexpect you don't want that unless you write a permission table. This would also mean your users are not tenanted.
If you want differnt users you can put it both the SHARED_APPS and the TENANT_APPS. Django Tenant alway queries local schema/tenant first and if that table doesn't exist it goes to the public schema. This is the way I do it with my project. Beware you need to make sure django.contrib.sessions in both SHARED & TENANT apps otherwise you will get a security problem swapping from one tenant to another.
The other think to look at is https://github.com/Corvia/django-tenant-users