Skip to main content

A Django app for multi-tenancy.

Project description

django-tenanet

Tenanet is a simple multi-tenancy framework for Django. It features a simple tenant data model, a middleware to handle tenant resolution, a context processor and a query manager to handle tenant data isolation.

Works well with django-allauth or other custom User models. TenantUser association is inlined in the default User admin form and the default User serializer.

A swappable Tenant metaclass is provided to allow for custom metadata (e.g. app-specific preferences, filters, feature flags, etc.) to be added to the Tenants.

Features

  • Tenant data model
  • Tenant middleware
  • Tenant query manager
  • Swappable Tenant metaclass

Requirements (tested)

  • Python 3.6+
  • Django 4.0+

Installation

pip install django-tenanet

Usage

Settings

Add tenanet to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'tenanet',
)

Add tenanet.middleware.TenantMiddleware to your MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = (
    ...
    'tenanet.middleware.TenantMiddleware',
)

Override the TENANET_TENANT_MODEL setting to point to your custom tenant model:

TENANET_TENANT_MODEL = 'myapp.MyTenantModel'

Models

TenantMeta

from tenanet.models import BaseTenantMeta

class MyTenantMeta(BaseTenantMeta):
    # Add custom tenant metadata fields here

Tenant scoped data with TenantDataModel

from tenanet.models import TenantDataModel

class MyTenantModel(TenantDataModel):
    # Add custom tenant data model fields here

Admin

TenantUser inline

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from tenanet.admin import TenantUserAssociationInline

class MyUserAdmin(UserAdmin):
    # your user admin config here
    inlines = (TenantUserAssociationInline,)

admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

License

This project is licensed under the terms of the Django-Tenanet Limited Use License. See the LICENSE file for license rights and limitations.

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-tenanet-0.1.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

django_tenanet-0.1.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file django-tenanet-0.1.1.tar.gz.

File metadata

  • Download URL: django-tenanet-0.1.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for django-tenanet-0.1.1.tar.gz
Algorithm Hash digest
SHA256 35606bd11a8589e4bdb7f7514bbb71a5d578047d944484428f739b3db9bdacdc
MD5 50d9394a65e2608f4db9ec69255e02aa
BLAKE2b-256 3a2a63eec920e62ecdab14bd41bf05ad25682334d319b5605c0a8484b37879c1

See more details on using hashes here.

File details

Details for the file django_tenanet-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_tenanet-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for django_tenanet-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f8f4597051d929f8b334259303079c0fbabcda3ab2cb61d9f2bb42d0e85dde9
MD5 0d1252e9386d4db8f5fb6d432c5fb9c5
BLAKE2b-256 a5af3943eb0a3217b60071a37ae5ed52ff994904350418f983e9a2f1c999bb6d

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