I'm really struggling with this whole app-idea. I read a lot of tutorials and style guides and I know I should try to create specialized apps, that do exactly one thing. This all makes sense when looking at some simple tutorial project but as soon as it gets to a complex real life project, I find myself unable to determine how I should draw the lines between different apps.
One of the problems is, that I want to have one site (or multiple sites) where the user sees a lot of different stuff. Stuff that should be from different apps, when following the app design rules. How would I realize something like this? My first idea was to create one app called ui
, that just handles ALL the views the actually lead to a template and all the other apps provide the models and helperfunctions. But I fear that the ui
app will become way to big.
To give you a small example: Lets I want to have a site where the user can do the following tasks:
Right now, I would create three apps:
But then, I would need some kind of main
or ui
app to handle how these apps interact and to create the actual site, where all the apps are somehow involved.
So, is there any "right" way to do this? Or are there any patterns that I can use? I would also appreciate links to good resources about this topic, even though I already read quite a few.
Django comes with six built-in apps that we can examine.
Any Django project consists of multiple applications.
A project refers to the entire application and all its parts. An app refers to a submodule of the project. It's self-sufficient and not intertwined with the other apps in the project such that, in theory, you could pick it up and plop it down into another project without any modification.
You just need to make sure your structure makes sense to you.
There's no requirement to create a new app for every feature that is bound to another part of the project's logic.
Reusable apps are a whole different story, their code should be unaware of the implementation to some extent.
Take a look at Django's structure for inspiration
A possible layout for your example:
project_root/ project/ __init__.py settings.py urls.py templates/ app1/ # override stuff static/ media/ app1/ __init__.py admin/ # as a package __init__.py subjects.py resources.py # etc models/ # as a package subjects.py resources.py # etc managers/ __init__.py subjects.py resources.py # etc services/ __init__.py audio.py # upload handler etc views/ __init__.py subjects.py urls/ __init__.py subjects.py templates/ app1/ subject_list.html # override at project level static/ app1/ css/ subject.css # override at project level app2/ __init__.py models.py # holds a Member model or whatever you require manage.py
I think the best way to delimit an app is roughly equivalent to the way you delimit a class on an Objected Oriented Programming Language. Instead of variables and methods, you think of models and views respectively:
models are the state of the object, views are used to see and interact with the state of the object.
My rule of thumb is, does creating an app help to encapsulate a specific set of models? If that is the case, then I try to create it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With