multitenant: update README

This commit is contained in:
Thomas NOËL 2015-02-05 18:36:06 +01:00
parent e75d051689
commit 2ba6f6bfef
1 changed files with 55 additions and 24 deletions

View File

@ -4,35 +4,34 @@ Multitenant
An application for making a Django application multitenant for Entr'ouvert
customers.
Based on https://django-tenant-schemas.readthedocs.org/
It is developed, tested and supported on Django 1.7, but it should work with
Django 1.6 + south.
Install
-------
See also : https://django-tenant-schemas.readthedocs.org/
Set the tenant model:
TENANT_MODEL = 'multitenant.Tenant'
Where are tenants:
TENANT_BASE = '/var/lib/<project>/tenants'
Add the middlewares for multitenant, they must be first:
MIDDLEWARE_CLASSES = (
'tenant_schemas.middleware.TenantMiddleware',
'entrouvert.djommon.multitenant.middleware.EOTenantMiddleware',
...
)
Add the multitenant filesystem template loader:
TEMPLATE_LOADERS = (
'entrouvert.djommon.multitenant.template_loader.FilesystemLoader'
....
)
Configure where the multitenant templates are located:
MULTITENANT_TEMPLATE_DIRS = ('/var/lib/my_project/templates/',)
Define the shared application:
'entrouvert.djommon.multitenant.middleware.TenantMiddleware',
'entrouvert.djommon.multitenant.middleware.JSONSettingsMiddleware',
'entrouvert.djommon.multitenant.middleware.PythonSettingsMiddleware',
) + MIDDLEWARE_CLASSES
Define the shared applications:
SHARED_APPS = (
'tenant_schemas',
@ -44,12 +43,15 @@ Define the shared application:
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
)
TENANT_APPS = INSTALLED_APPS
INSTALLED_APPS += ('tenant_schemas', 'entrouvert.djommon.multitenant')
INSTALLED_APPS = ('entrouvert.djommon.multitenant',
'tenant_schemas') + INSTALLED_APPS
# or, with Django 1.6 or older:
# INSTALLED_APPS += ('tenant_schemas', 'entrouvert.djommon.multitenant')
Use multitenant database engine:
@ -59,9 +61,38 @@ Use multitenant database engine:
'NAME': '<db_name>',
},
}
DATABASE_ROUTERS = (
'tenant_schemas.routers.TenantSyncRouter',
)
Use multitenant south adapter:
# With Django 1.6 or older, use multitenant south adapter:
# SOUTH_DATABASE_ADAPTERS = {'default': 'south.db.postgresql_psycopg2'}
SOUTH_DATABASE_ADAPTERS = {
'default': 'south.db.postgresql_psycopg2',
}
Add the multitenant filesystem template loader and configure where the
multitenant templates are located:
TEMPLATE_LOADERS = (
'entrouvert.djommon.multitenant.template_loader.FilesystemLoader',
) + TEMPLATE_LOADERS
TENANT_TEMPLATE_DIRS = (TENANT_BASE,)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
) + TEMPLATE_CONTEXT_PROCESSORS
Usage
-----
Create a tenant:
manange.py create_tenant www.example.net
Migration of all tenants:
manange.py migrate_schemas
Tenants are created in TENANT_BASE directory, for example :
/var/lib/project/tenants/www.example.net/
templates/ <-- override project templates
static/ <-- to be handled by HTTP server
media/
Each tenant is a PostgreSQL schema, named www_example_net