Reputation: 10639
I usually have plain python objects in my Django project that have specific responsabilities like observers, strategy objects, factories, etc. Where should I place those for a more organized file structure? There is a pattern in the industry for that?
Upvotes: 0
Views: 304
Reputation: 77902
There's nothing like an "industry standard" here. Django does have some expectations about django-specific stuff (models, custom template tags and filters, management commands etc) and a couple conventions (the views and urls modules for example - you can technically name them however you want, but everyone expects them to be named "views" and "urls"), but everything else is just plain python code and can be organized however it makes sense to you. The only recommandations here are the obvious ones - high cohesion, low coupling, etc...
Upvotes: 3
Reputation: 111
I can't comment on how widely this is adopted or if it is the right way, personally I follow the project structure outlined in the Two Scoops of Django book. A similar setup is outlined here https://django-project-skeleton.readthedocs.io/en/latest/structure.html as such:
[projectname]/ <- project root
├── [projectname]/ <- Django root
│ ├── __init__.py
│ ├── settings/
│ │ ├── common.py
│ │ ├── development.py
│ │ ├── i18n.py
│ │ ├── __init__.py
│ │ └── production.py
│ ├── urls.py
│ └── wsgi.py
├── apps/
│ └── __init__.py
├── configs/
│ ├── apache2_vhost.sample
│ └── README
├── doc/
│ ├── Makefile
│ └── source/
│ └── *snap*
├── manage.py
├── README.rst
├── run/
│ ├── media/
│ │ └── README
│ ├── README
│ └── static/
│ └── README
├── static/
│ └── README
└── templates/
├── base.html
├── core
│ └── login.html
└── README
If I want to create objects and functions accessible to all apps I create a utils
module at the app level. If I am creating utility functions and objects specific to an app I place the utils
module in the app directory. Just personal preference really.
Hope it helps.
Upvotes: 0