An app for a cleaner Django
Project description
Django the Domain Driven Design way
This is a proof of concept to model django apps on a domain driven design way. The idea is to move Django app related stuff under infrastructure folder, so ideally an app folder structure would be:
app_folder/
application/
domain/
infrastructure/
migrations/
admin.py
models.py
__init__.py
__init__.py
Installation
To install from source, download the source code, then run this:
python setup.py install
Or install with pip
pip install django-ddd
Configuration
Select your desired app folder structure and add these settings to your project.
CUSTOM_MODELS_MODULE
Where Django should look for your app models.
Default:
models
Example:
infrastructure.models
CUSTOM_MIGRATIONS_MODULE
Where Django should look for your app migrations.
Default
migrations
Example:
infrastructure.migrations
CUSTOM_ADMIN_MODULE
Where Django should look for your app admin configuration.
Default
admin
Example:
infrastructure.admin
Usage
To use custom locations
Install django-ddd to your project requirements and add settings so Django
can find your apps modules as seen on configuration.
You don't need to add django-ddd it to INSTALLED_APPS
Then, on your package apps.py
import django-ddd custom app config:
from django_ddd.apps_config import CleanAppConfig
class AppNameConfig(CleanAppConfig):
name = "app_name" # package folder name
On the app package __init__.py
add where to find your app config. If it is in
app_name.infrastructure.apps.py
:
default_app_config = "app_name.infrastructure.apps.AppNameConfig"
Add your new application to INSTALLED_APPS
To use start_clean_app
This command creates a new Django app with a Domain Driven Design structure.
To use it, you need to add django-ddd to your INSTALLED_APPS
:
INSTALLED_APPS = [
# ...
"django_ddd",
# ...
]
Then, just call:
python manage.py start_clean_app app_name
This will create a new context with previously seen structure:
app_name/
application/
domain/
infrastructure/
migrations/
admin.py
models.py
__init__.py
__init__.py
Here all Django details are under infrastructure
folder. Package level __init__.py
has route to app config:
default_app_config = "app_name.infrastructure.apps.AppNaemAppConfig"
You can move this folder to your sources
and add it to INSTALLED_APPS
so Django can recognize it.
Contributing / Running project locally
Build the docker image:
docker build . -t django-ddd-dev
Run tests:
docker run -v $(pwd)/.:/usr/src/app django-ddd-dev bash -c "pipenv run python manage.py test"
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
Hashes for Django_ddd-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d869abdb146b215c86b0dc693f80b5e827765c2b1487a9d808b879ead0ce8499 |
|
MD5 | 9107b844f5807d6c9cf3b2838b14f998 |
|
BLAKE2b-256 | 3cd99cc13230c8596721c82fd4f1921f43d10a652d57d87349a5120624780d75 |