6 ms·
So you’d prefer one file with all models? Do you break out into apps for business logic? Keep models in one app/file. Then domain driven design elsewhere?
by trojans1290 2mo ago
So you’d prefer one file with all models? Do you break out into apps for business logic? Keep models in one app/file. Then domain driven design elsewhere?
- pdhborges 2mo agoYou don't have to put all your modules into a single file. You can break them into multiple files and the import them into a model file just so that Django loads it from the expected location. Instead of apps you can just split your components inside a single app using regular python modules.
- 3eb7988a1663 2mo agoAs things get more complicated, I will separate out by some kind of concept. Which can be something as simple as: /coreapp /forms_foo.py /forms_bar.py /models_bar.py /models_foo.py /views_bar.py /views_foo.py You can do a more sophisticated module layout, but essentially something as straightforward as the above, all under a single "core" application. Prevents Django from fighting you when you want to work across the arbitrary "app" boundary.
- selcuka 2mo agoYou can also have a /models/ package with foo.py, bar.py under it. It is easier to maintain. As an additional bonus, you can add an __init__.py that imports all models if you want to be able to do a `from .models import FooModel`.