Hi, I would appreciate some ideas how to best implement a new feature. Before I get to that, some words about my current project structure.
As someone following Django recommendations (as per tutorial) my project consists of multiple apps. Something, which always gave me headaches, because the boundary of apps are rarely visible like a red line painted on the asphalt. Remove any single app from my project, and my project won’t start any longer.
Anyways, I have a couple of static pages like Home, Legal, or Privacy, that I decided to serve from the project folder where my settings.py resides. You find my folder structure below (I changed the naming for better understanding).
. ├── polls │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── management │ ├── migrations │ ├── models.py │ ├── templates │ ├── templatetags │ ├── tests.py │ ├── urls.py │ ├── utils.py │ ├── validators.py │ └── views.py ├── mysite │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ ├── views.py │ └── wsgi.py ├── other_apps ├── templates │ ├── base.html │ ├── home.html │ ├── legal.html │ └── privacy.html …
As you can see, there is a
views.py file beside my
settings.py, which does nothing more than:
@login_required def home(request): return render(request, "home.html") @login_required def legal(request): return render(request, "legal.html") @login_required def privacy(request): return render(request, "privacy.html")
The templates for this are in a
templates folder on the same level as
polls app does send different types of emails to different groups of users.
There are two “moderators” who have elevated permissions, but are not administrators and have no access to the admin page.
The New Feature
The moderators should be able to edit the contents of Home, Legal, and Privacy. They should also be able to edit the email template for some of the emails that are sent to the users.
I clearly need a model to store both, the content of the pages as well as the content of the emails. The model will have a unique key, that takes the contents of an enum, so there is a 1:1 relationship between each instance and the target use-case (Home, Legal, Privacy, Email Template 1, Email Template 1, …) I will have to go through the different apps, to hook up implement the new feature.
My headaches start again when I think of how to place this feature, especially the model, into my project. Should I create a new app “editable_templates” where I place the model for all the pages and email templates – or should I create a model in each app, because there will not be a single template that is shared between apps. And if I split up the apps, then where to place the pages logic, that is now a simple view in my project folder. I would have to add a model to it, which also is kind of ugly.
I would also need a place where the user can edit the content. Ideally centralised under a new url “/settings”, but where do I place that stuff then.
Looking for some input or ideas.