🧭 Multi-tenancy
With multi-tenancy, one admin serves several tenants, such as the organizations of a platform. Editors pick a tenant and only see and change that tenant's content.
Set it up
-
Point the
TENANT_MODELsetting at your tenant model:# mysite/settings.pyCONTENT_STUDIO = {"TENANT_MODEL": "organizations.models.Organization",} -
Give each model that belongs to a tenant a foreign key to the tenant model. Content Studio finds it on its own: the one foreign key that points at the tenant model. Models without one are shared by all tenants.
How content is scoped
Editors choose a tenant in the admin, and everything they do happens within it:
- Lists and searches only show the selected tenant's objects.
- New objects are assigned to the selected tenant.
- Without a selected tenant, tenant models show no objects at all.
- A tenant the editor may not access is refused.
Decide who works in which tenant
The site's get_tenants method decides which tenants an editor may work in.
It feeds the tenant selector and guards every page, so this one method is
all the authorization multi-tenancy needs. By default it returns all
tenants:
# mysite/studio.py
from content_studio.admin import ContentStudioSite
class BlogStudioSite(ContentStudioSite):
def get_tenants(self, tenant_model, **kwargs):
user = kwargs["request"].user
return tenant_model.objects.filter(members=user)
admin_site = BlogStudioSite()
Point the ADMIN_SITE setting at the site to
use it.