Skip to main content

A re-useable Django app for building models that modify Django settings.

Project description

Settings Model

TravisCI PyPI Coveralls Code Style

Documentation: https://django-settings-model.readthedocs.io

Source: https://github.com/gregschmit/django-settings-model

PyPI: https://pypi.org/project/django-settings-model/

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 Settings example 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 wsgi.py/manage.py 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 incrond to 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 (settings_model) in your INSTALLED_APPS and running migrations, or you can create your own custom settings model, inheriting from settings_model.models.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 settings.py file:

try:
    from .model_settings import *
except:
    pass

If you create a custom Settings model, then ensure you set the __settings_filename__ 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.

Settings

  • SETTINGS_MODEL_REBOOT_FILES (default []): 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 BASE_DIR/manage.py and the wsgi.py file defined by WSGI_APPLICATION.

Contributing

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-settings-model-0.5.2.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

django_settings_model-0.5.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file django-settings-model-0.5.2.tar.gz.

File metadata

  • Download URL: django-settings-model-0.5.2.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for django-settings-model-0.5.2.tar.gz
Algorithm Hash digest
SHA256 dc4e5717e02663ba61e6c913ebc42876b58027dbf6f37f66b1516ab509513d3e
MD5 fb9a0ca9f6bc5c852a3243d23e9f2207
BLAKE2b-256 08418ea6513085a1f78f8e9b64f479557d9798254cae0a56397d07942ba5a065

See more details on using hashes here.

Provenance

File details

Details for the file django_settings_model-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: django_settings_model-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for django_settings_model-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fe126c6ac3d1420f7d75c15c2c87e1d6649bd17c353d1fad5ed892df1f52620d
MD5 8a96235477dd1974274d587d05c5e952
BLAKE2b-256 200509d5cd8dc1fb7a1d9ace75b30f484587d49cc8a3da8c32530999bcd09965

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page