This is a Django project template with all necessary stuff to run a functional project without more changes.
- Organization model with some basic attributes.
- User model (from Abstract model) with foreign key to Organization model.
- User's email to login (
username
field is copied from email). - Rest API support:
- Login. Obtain access token and refresh access token.
- Return user info with tokens at login.
- CORS headers allowing all hosts.
- Swagger docs.
- Tenant apps via django-tenant-schemas.
- Organization model is the tenant base.
core
app is shared (inpublic
schema).- Use
migrate_schemas
instead of built-inmigrate
command. - Custom middleware to select
schema_name
from the request's header (X-DTS-HEADER
). Default schema ispublic
.
You must have installed Django on your system to use django-admin
command.
- Create a new project by running:
django-admin startproject --template https://github.com/christianmtr/my_django_template/archive/master.zip --extensions=py,json new_django_project .
- Create and active an virtual environment:
python -m venv venv
source venv/bin/activate
Only works with Python 3.X, use
python3
if is necessary.
-
Change the database parameters in
settings.py
at line 77. -
Install dependencies from
requirements.txt
by running:
pip install -r requirements.txt
- Create migration files:
python manage.py makemigrations
- Apply migrations:
python manage.py migrate_schemas
- Create
public
tenant:
python manage.py loaddata organization
- Create own organization:
python manage.py create_public_organization
- Create a super user specifying
schema
name:
python manage.py createsuperuser
- Run project:
python manage.py runserver
- Enjoy =)
Check out the other branches.