1024programmer Java Django where to put the shared models and logic – Django where to put the shared models and logic

Django where to put the shared models and logic – Django where to put the shared models and logic

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
  • Each worker class should get its 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 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 put these worker processes? And how should I run them?
  • 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.

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/772202

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索