Adds multitenancy based on django_tenants to wagtail cms
Project description
wagtail-tenants
wagtail_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 start
Installation
pip install wagtail-tenants
Configuration
-
Add "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) + [ app for app in TENANT_APPS if app not in SHARED_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 the django_tenants backend:
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 --shared
-
Create a public schema with
./manage.py create_tenant
and usepublic
as the schema name andlocalhost
-
Create a superuser for the public tenant
./manage.py create_tenant_superuser
-
Start the Server and have fun
-
You 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_superuser
for that.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for wagtail_tenants-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e71e000678028b673a6c0a8170918d6043104d712a883c80f7b02580b3343648 |
|
MD5 | b0a250dbc0f95a745ec2b57f048dbf5a |
|
BLAKE2b-256 | ec03121c424484d63868cf09d64c1794ab76b182323fa1eec2adba8f7347535d |