I Have the following folder setup:
I have the following folder setup:
- myproject
- web
- worker
The web project is a website containing the typical django setup and all, including the model and some service classes which move the logic away from the views. The website will display data coming from a database. The worker folder contains 2 classes which are filling the database and aggregate it. These 2 classes are like background processes. My question is, how should I structure this?
A web project is a website with a typical Django setup, including models and some service classes that move logic away from views. The website will display data from the database. The worker folder contains 2 classes that populate the database and aggregate it. These two classes are like background processes. My question is, how should I build this?
- Should each worker class get his own application folder
- If so, I would prefer to move the models out of the web project in the myproject folder, since they are shared between the applications. However this seems to be against the django convention, why so? And how would the convention handle this?
- If not, where should I put these worker processes? And how should I run them?
Each worker class should get its own application folder
If this is the case, I would rather move the models out of the web project in the myproject folder since they are shared between the applications. However, this seems to be against Django convention, why? How will the conference deal with this issue?
If not, where should I place these workflows? What should I do?
Thanks in advance!
Thanks in advance!
2 solutions
#1
0
Usually if I have stuff to be shared between different sections I either: 1) make a lib and install it via pip 2) make a helper folder within the project
Usually, if I have something shared between different parts, I either: 1) create a lib and install it via pip 2) create a Help folder
#2
0
Keep the project and the app(s) separate and create proper Python packages to handle dependencies. I.e.
Keep projects and applications separate and create appropriate Python packages to handle dependencies. That is
src/sites/web <-- the project, containing manage.py, settings and root urls
and
src/apps/myapp <-- the app, containing models, views, etc
src/apps/myapp/worker <-- strongly related functionality
in src/sites/web/setup.py
(and/or requirements.txt
) you would add myapp
as an (install ) dependency.
In src/sites/web/setup.py (and/or requirements.txt) you add myapp as an (installation) dependency.
If worker
is only loosely related functionality, then a separate package would make sense, e.g.:
If workers only have loosely related functionality, then separate packages make sense, for example:
src/lib/worker
where src/lib/worker/setup.py
(and/or requirements.txt
) would add myapp
as a dependency, and src/sites/web/setup.py
would add worker
as a dependency.
where src/lib/worker/setup.py (and/or requirements.txt) will add myapp as a dependency, and src/sites/web/ setup.py will add worker as a dependency.