being new to Django (v3.x) I'm trying to write an IDE-like app that allows to:
- Create new "work projects" (not as in Django projects, but as in work projects like in an IDE, where each created work project later on contains various artefacts and files)
- always in the context of a project upload files to that project and then work with them.
Hence, the structure of my Django app should look like so:
myapp/
/project/
/file_1
/file_2
/file_3
Accordingly, following best practices of how to build URIs the URL patterns probably ultimately should look like:
myapp/project/<int:project_pk>/file/<int:file_pk>/
What I don't fully understand is: How can I cause Django to always work in the context of a pre-selected project?
Either I do it all in a stateless fashion where users always need to specify the full URL including the project primary key. Problem is that my templates may not know what primary key the current project has, which may cause issues with reverse URLs and the like.
Or I somehow keep the current project primary key as state in some kind of non-global but shared variable among all resources in the same project. Here the problem is obviously how to invalidate the state at the right time etc.
Furthermore, should I use a flat structure of apps (e.g. project, project_files, project_users etc.), or should I nest all my apps under a project app (e.g. project, project.files, project.users etc.)?
What are best practices for such a situation in Django (> v3)? Is there any simple sample app that has such a structure where I could look it up?