Skip to main content

A lightweight application to use Django as SaaS (Software as a Service). It separates users databases for the same Django instance.

Project description

# django-saas-userdb
A lightweight application to use Django as SaaS (Software as a Service). It separates users databases for the same Django instance.

## Installation

```
pip install django-saas-userdb
```

## Configuration

In your settings:
```
DATABASE_ROUTERS = ['userdb.routers.AuthRouter', 'userdb.routers.DatabaseRouter']
```

You must configure the field used in request.user to determine the used database. For example, this code :
```
SAAS_DBNAME_FIELD = 'username'
```
will need a Database for each user, postfixed with "_db" (for example users named "foo" and "bar" will be using databases with names "foo_db", "bar_db").

Note: For any user with no database configured for him, it will fallback to 'default' database.

The database file must be separated from settings file (to be easlily updated). If you want to use the command *add_database*, you also need to have the flag "###ADD_DATABASE" in this file (see example below).
An example of database file (following previous example):
```
DATABASES = {
# The default database
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'default.sqlite3'),
},
# The database for users (must be separated to allow registration before DB choice)
'auth_db': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'users.sqlite3'),
},
# The database for "foo" user
'foo_db': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'foo.sqlite3'),
},
# The database for "bar" user
'bar_db': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'bar.sqlite3'),
},
###ADD_DATABASE
}
```


Project details


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
django_saas_userdb-0.1.dev17-py2.py3-none-any.whl (6.5 kB) Copy SHA256 hash SHA256 Wheel py2.py3
django-saas-userdb-0.1.dev17.tar.gz (5.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page