This Django reusable app implements a base
SettingsModel class to allow settings to
be edited and saved in the database. For any particular project, you probably want to
customize which settings are exposed, so while there is a
implementation that you can use, the abstract model
SettingsModel can be used to
construct your own settings model(s), and things like webserver restarts are handled in
the abstract model class.
The Problem: Sometimes you want to build an app that can be managed by non-developers, and things like timezone, hostname, or SMTP settings may need to be editable from the UI.
The Solution: This app implements a base
SettingsModel class that allows you to
expose settings to a user interface via the database. It writes these stub settings to
separate files which you try/include at the end of your main settings file. This way
you have sensible defaults, but when the user created/edits a model file in the UI,
those settings override. There is a mechanism to touch the
files when saving, so the only thing left to do is either configure your web server to
watch those files and reboot when they are touched, or use a tool like
watch those files and trigger your webserver to reboot when they are touched.
How to Use
$ pip install django-settings-model
You can use the builtin
Settings model by including this app (
INSTALLED_APPS and running migrations, or you can create your own custom
settings model, inheriting from
settings_model.base.SettingsModel. If you want to
build a custom settings Model, use the
Settings model as a reference implementation.
For the included
Settings model, you need to add the following to the end of your
try: from .model_settings import * except: pass
If you create a custom Settings model, then ensure you set the
appropriately (avoid conflicts with other settings models), and ensure you call its
.init() class method in the application's
AppConfig.ready() method. This will
update the settings with the true values (and optionally create an initial settings
model instance) on startup.
): This is a list of files that should be touched when the settings model is saved to signal to the webserver to reboot. If it is falsy, then the system will try to find and touch the file
wsgi.pyfile defined by
Submit a pull request if you would like to contribute. You must only contribute code that you have authored or otherwise hold the copyright to, and you must make any contributions to this project available under the MIT license.