Skip to main content

A small package to create tenants,schemas and domains only by providing a name.

Project description

customers

customers is a Django app which is used to serve django tenant details. It is used to create tenants, schemas and doamin urls for respective tenants. :fire:

Quick start

Install the package pip install dj-auto-tenant.

Now make change in your DATABASE_ENGINE

DATABASES = {
    'default': {
        'ENGINE': 'django_tenants.postgresql_backend',
        # ..
    }
}

Add DATABASE_ROUTERS setting, so that the correct apps can be synced, depending on what’s being synced (shared or tenant).

DATABASE_ROUTERS = (
    'django_tenants.routers.TenantSyncRouter',
)

Add the middleware django_tenants.middleware.main.TenantMainMiddleware to the top of MIDDLEWARE, so that each request can be set to use the correct schema.

MIDDLEWARE = (
    'django_tenants.middleware.main.TenantMainMiddleware',  # If subdomain based tenant
    'django_tenants.middleware.TenantSubfolderMiddleware',  # If subfolder based tenant
    #...
)

Now change your INSTALLED APPS settings and seprate your shared apps and tenant apps. Add your customers app in SHARED APP.

SHARED_APPS = (
    'django_tenants',  # mandatory
    'customers', # you must list the app where your tenant model resides in

    'django.contrib.contenttypes',

    # everything below here is optional
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
)

TENANT_APPS = (
    # The following Django contrib apps must be in TENANT_APPS
    'django.contrib.contenttypes',

    # your tenant-specific apps

    'myapp.houses',
)

INSTALLED_APPS = list(SHARED_APPS) + [app for app in TENANT_APPS if app not in SHARED_APPS]

Add: TENANT_MODEL = "customers.Client" # app.Model

TENANT_DOMAIN_MODEL = "customers.Domain"  # app.Model

CLOUDAMQP = "<YOUR CLOUDAMQP URL>"

Now migrate customers python manage.py migrate_schemas --shared

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

dj_auto_tenant-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_auto_tenant-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file dj_auto_tenant-0.1.0.tar.gz.

File metadata

  • Download URL: dj_auto_tenant-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for dj_auto_tenant-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ce6efd6922503829e434ae696bc9e9bfe723088f6d7c71367144cc0143547574
MD5 a3bdc85c755e87c01dc81e6eb3fb000c
BLAKE2b-256 4967698ed227f5988037fbf27aaf3d744551abab79764c6fb99d9317a043666a

See more details on using hashes here.

File details

Details for the file dj_auto_tenant-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dj_auto_tenant-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for dj_auto_tenant-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 117d80d20456e28c568ef01d58ac2d158bfa645c56c478d1fdb320c7b40e2e9b
MD5 3257d7e30d1c0c86a066d9e867c59094
BLAKE2b-256 5c1bc9398d5b4ca9391a96f0c9606d74c83b43c0903cd8603eb7b33447331f3b

See more details on using hashes here.

Supported by

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