Skip to main content

Multitenant support for Django, using one tenant per database.

Project description

1. Install

$ pip install django-rds-db-multitenant

2. Implement a mapper

3. Update settings.py

Set the multitenant mapper by specifying the full dotted path to your implementation (in this example, mapper is the name of file mapper.py):

MULTITENANT_MAPPER_CLASS = 'myapp.mapper.TenantMapper'

Install the multitenant middleware as the first middleware of the list (prior to Django 1.10, you must use the MIDDLEWARE_CLASSES setting):

MIDDLEWARE = [
    'rds_db_multitenant.middleware.MultiTenantMiddleware',
    ....
]

Change your database backend to the multitenant wrapper:

DATABASES = {
    'default': {
        'ENGINE': 'rds_db_multitenant.db.backends.mysql',
        'NAME': 'devnull',
    }
}

Note: the NAME is useless for MySQL but due to a current limitation, the named database must exist. It may be empty and read-only.

Optionally, add the multitenant helper KEY_FUNCTION to your cache definition, which will cause cache keys to be prefixed with the value of mapper.get_cache_prefix:

CACHES = {
  'default' : {
        'LOCATION': '127.0.0.1:11211',
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'KEY_FUNCTION': 'rds_db_multitenant.cache.helper.multitenant_key_func'
    }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-rds-db-multitenant-0.3.3.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file django-rds-db-multitenant-0.3.3.tar.gz.

File metadata

  • Download URL: django-rds-db-multitenant-0.3.3.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for django-rds-db-multitenant-0.3.3.tar.gz
Algorithm Hash digest
SHA256 5dbfb476744c8e134c9c8b9c825372166085f34c18d836d972226ae103b4a02c
MD5 5979ac6950376f1c27d8ae31380e73de
BLAKE2b-256 9c26e21a36dc2a3ceb9e5b89efcc105588936b3fb83727536c1666ea64c76188

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page