Package: wagtail-tenants
wagtail-tenantswagtail_tenants is a Django/Wagtail app to provide multitenancy to your wagtail project.
You are able to run a main Wagtail Site and from within you are able to host as many Wagtailsites as you want.
django_tenants is used to slice the database layer in a postgres database based on a given schema.Detailed documentation will be in the "docs" directory.Quick startInstallationpipinstallwagtail-tenantsConfigurationAdd "wagtail_tenants" to your INSTALLED_APPS setting like this:SHARED_APPS=('wagtail_tenants.customers','wagtail_tenants','wagtail.contrib.forms',..."wagtail_tenants.users","wagtail.users",...)TENANT_APPS=('wagtail_tenants',"django.contrib.contenttypes",...# rest of the wagtail apps..."wagtail_tenants.users","wagtail.users",...)INSTALLED_APPS=list(SHARED_APPS)+[appforappinTENANT_APPSifappnotinSHARED_APPS]Include the the tenants middleware at the beginning of your middlewares:MIDDLEWARE=["wagtail_tenants.middleware.main.WagtailTenantMainMiddleware",...]Define the Tenant model Constants (and also set the default auto field if not already done):AUTH_USER_MODEL='wagtail_tenants.User'TENANT_MODEL="customers.Client"TENANT_DOMAIN_MODEL="customers.Domain"DEFAULT_AUTO_FIELD='django.db.models.AutoField'Set the Database backend to thedjango_tenantsbackend:DATABASES={"default":{"ENGINE":"django_tenants.postgresql_backend","NAME":"db_name","USER":"db_user","PASSWORD":"","HOST":"127.0.0.1","PORT":"5432",}}Set the Database Router to work with the tenants:DATABASE_ROUTERS=("wagtail_tenants.routers.WagtailTenantSyncRouter",)Set the authentication backend to fit to our Tenant model.AUTHENTICATION_BACKENDS=['wagtail_tenants.backends.TenantBackend',]Run the migrations with./manage.py migrate_schemas --sharedCreate a public schema with./manage.py create_tenantand usepublicas the schema name andlocalhostCreate a superuser for the public tenant./manage.py create_tenant_superuserStart the Server and have funYou are able to create tenants within the admin of your public wagtailsite. If you want to log into a tenant you need at least one superuser for the tenant. You can use./manage.py create_tenant_superuserfor that.Update 0.1.10The new version of wagtail_tenants is now able to archive the follwing features:wagtail 4.2. supportAs the developemt of wagtail still goes on, so we do. Wagtail incuded a reference index for models it was necessary to handle this feature, as we don 't need this feature on our tenant models.Create tenantaware appsOnly users of a given tenant are able to interact within the wagtail admin with that kind of app.
This works in two ways:Add a tenantaware property to the apps AppConfig class inyourtenantapp.apps.pyin theadmin.pycreate a ModelAdmin or ModelAdminGroup for your app and use themenu_item_nameproperty to fit to your apps name from your AppConfig. If this fits the app will be hidden for all tenants withou a TenantFeaure of the same name. This feature is good for providing different tiers of your app (eg. free | premium )You can specify the tenant directly within the AppConfig so that only users of the tenant have access to this app. This is necessary if you want to create complete and complex functionality only for one tenant. To archive this you have to add theWagtailTenantPermissionMiddlewareto your middlewares in your settings like so:MIDDLEWARE=["wagtail_tenants.middleware.main.WagtailTenantMainMiddleware","wagtail_tenants.middleware.main.WagtailTenantPermissionMiddleware","..."]Exclude permissions from normal users in the group create and group edit viewWe are able to hide apps from the group create and group edit views in the wagtail admin. With this approach it is possible to create a tenant admin group with all permissions and distribute it to a tenant user. The tenant admin is able to create and edit groups, but you can decide which apps should be excluded from the view. By default this should include all customers apps. But feel free to extend the list.TENANT_EXCLUDE_MODEL_PERMISSIONS=["customers.Client","customers.ClientFeature","customers.Domain","customers.ClientBackup",]