1
|
Multitenant
|
2
|
-----------
|
3
|
|
4
|
An application for making a Django application multitenant for Entr'ouvert
|
5
|
customers.
|
6
|
|
7
|
Install
|
8
|
-------
|
9
|
|
10
|
Set the tenant model:
|
11
|
|
12
|
TENANT_MODEL = 'multitenant.Tenant'
|
13
|
|
14
|
Add the middlewares for multitenant, they must be first:
|
15
|
|
16
|
MIDDLEWARE_CLASSES = (
|
17
|
'tenant_schemas.middleware.TenantMiddleware',
|
18
|
'entrouvert.djommon.multitenant.middleware.EOTenantMiddleware',
|
19
|
...
|
20
|
)
|
21
|
|
22
|
Add the multitenant filesystem template loader:
|
23
|
|
24
|
TEMPLATE_LOADERS = (
|
25
|
'entrouvert.djommon.multitenant.template_loader.FilesystemLoader'
|
26
|
....
|
27
|
)
|
28
|
|
29
|
Configure where the multitenant templates are located:
|
30
|
|
31
|
|
32
|
MULTITENANT_TEMPLATE_DIRS = ('/var/lib/my_project/templates/',)
|
33
|
|
34
|
Define the shared application:
|
35
|
|
36
|
|
37
|
SHARED_APPS = (
|
38
|
'tenant_schemas',
|
39
|
'entrouvert.djommon.multitenant',
|
40
|
# those are needed for the public apps to work
|
41
|
# add also any application needed by the public app
|
42
|
'django.contrib.auth',
|
43
|
'django.contrib.contenttypes',
|
44
|
'django.contrib.sessions',
|
45
|
'django.contrib.messages',
|
46
|
'django.contrib.staticfiles',
|
47
|
'django.contrib.sites',
|
48
|
)
|
49
|
|
50
|
TENANT_APPS = INSTALLED_APPS
|
51
|
|
52
|
INSTALLED_APPS += ('tenant_schemas', 'entrouvert.djommon.multitenant')
|
53
|
|
54
|
Use multitenant database engine:
|
55
|
|
56
|
DATABASES = {
|
57
|
'default': {
|
58
|
'ENGINE': 'tenant_schemas.postgresql_backend',
|
59
|
'NAME': '<db_name>',
|
60
|
},
|
61
|
}
|
62
|
|
63
|
Use multitenant south adapter:
|
64
|
|
65
|
SOUTH_DATABASE_ADAPTERS = {
|
66
|
'default': 'south.db.postgresql_psycopg2',
|
67
|
}
|