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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-tenanet-0.1.0.tar.gz.
File metadata
- Download URL: django-tenanet-0.1.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68372f491d9dfbd9fd5e88614ceb666b8257bf4f3f09a293ccf4bb8b152f0c08
|
|
| MD5 |
35306a3977f60c9bf009ad9b9278146c
|
|
| BLAKE2b-256 |
c1c5b2911e1df3dcd988dcdc581a2c1cf811da2d9fd8d51df5b5822d44432005
|
File details
Details for the file django_tenanet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_tenanet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a433c5b750c94420b135401dd0cf114bee48024c568dd961f57112a304364ae
|
|
| MD5 |
15dd6664c31acc9d4e32bdf4198a9cf9
|
|
| BLAKE2b-256 |
22bab3fc28618ec2780b5fb8e050c0649698238b6882e98ab0ec12d494b74a73
|