is the core model which establishes a hierarchy for linking apps (including payments, teams) and users.
Tenant logic is applied to the data layer. Tenants share the same database and schema. There is a main tenant table, to which all other Tenant-Aware tables must be linked via foreign keys.
Queries are filtered based on the tenant_id for the tenant-aware models. Each tenant model includes a custom manager for filtering the queryset based on the tenant.
- Important All users must be linked to a tenant. Depending on the configuration (see Tenant Modes below) this can be to more than one tenant.
- Important For all other tenant aware models, the model must be linked to only one tenant
The model should subclass
TenantModelMixinwhich inserts a tenant_id field on the model.
The model manager should subclass the
objectsmanager must be replaced with the new custom manager.
Please note that this is distinct from the Teams feature.
An app can be in one of three TenantModes:
The tenant mode must be set up during configuration but can be changed from
SINGLE_TENANT - All users belong to the same tenant. i.e. One workspace for all tenants.
Single Tenant Created
- All users belong to the same tenant
- Teams features enabled
- An example usecase is internal tools for a single organisation
Example Internal Marketing Dashboard For a Company
SINGLE_TENANT_PER_USER - User belongs to one tenant. Tenant/Workspace cannot have more than one user.
Only one user per tenant
- Every user belongs to one tenant
- Invitation to external users flow disabled
- Teams feature is also disabled
Most commonly used by SaaS or B2C products. ExampleSocial App where users will always have an individual account.
MULTI_TENANT_PER_USER - User belongs to multiple tenants/workspaces. Each tenant/workspace can have multiple users
Multiple Users per Tenant
- Each user can switch between tenants
- example, your typical SaaS application - a unified messaging SaaS platform.
User Tenant roles
Each user is assigned one of the following roles:
ROLE_MEMBER = "member" ROLE_MANAGER = "manager" ROLE_OWNER = "owner" - assigned to a single user, the owner of the workspace.
Tenant roles for managers and members can be changed by owners directly from the dashboard.