django-database-for-apps

Django router for apps with more than 1 database


Keywords
django, database, router
License
Other
Install
pip install django-database-for-apps==0.1.1

Documentation

https://travis-ci.org/dex4er/django-database-for-apps.svg?branch=master https://readthedocs.org/projects/django-database-for-apps/badge/?version=latest

django-database-for-apps

django-database-for-apps is a package that provides a router which chooses a database based on app name.

Installation

Install with pip or pipenv:

pip install django-database-for-apps

Add django_database_for_apps to your installed apps in your settings.py file:

INSTALLED_APPS = [
    'django_database_for_apps',
    ...
]

Configure DB routers:

DATABASE_ROUTERS = [
    'django_database_for_apps.Router'
]

Configuration

# list of apps and theirs database
DATABASE_FOR_APPS = {
    'test_project': 'default',
    '*': 'django',
}

* matches all applications so the default database might be redefined from 'default' to something else.

Optional

# allows relations between databases (default: None)
DATABASE_FOR_APPS_RELATIONS = True

Documentation

See http://django-database-for-apps.readthedocs.org/

License

Copyright © 2019, Piotr Roszatycki

This software is distributed under the GNU Lesser General Public License (LGPL 3 or greater).