Django app to manage project related settings from forms.
Settings attributes are stored into JSONField in database so there is no need to migrate if you need to add new attributes.
pip install git+ssh://[email protected]/COEXCZ/django_system_settings.git
Add to settings.py
Add to settings.py
INSTALLED_APPS = [
...
'system_settings',
...
]
Add attributes and settings anywhere in your project
from django import forms
from system_settings import SettingsAttributes, SettingsAttribute, InMemorySystemSettings
class MySettingsAttributes(SettingsAttributes):
my_settings_attribute = SettingsAttribute(
form_field=forms.CharField,
form_field_kwargs=dict(
label='My settings attribute',
widget=forms.Textarea
)
)
my_settings_attributes = MySettingsAttributes()
class MySettings(InMemorySystemSettings):
name = 'my_settings'
attributes = my_settings_attributes
my_settings = MySettings()
from system_settings.forms import SystemSettingsForm
class MySettingsForm(SystemSettingsForm):
settings_attributes = my_settings_attributes
from system_settings.views import SystemSettingsView
class MySettingsView(SystemSettingsView):
settings = my_settings
form_class = MySettingsForm
template_name = "user/preferences/my_settings.html"
To not ask database for every access of settings attrs there is caching layer.
InMemorySystemSettings
settings are stored in app memory during runtime. Suitable for apps deployed as single process.
CachedSystemSettings
settings using django cache. By default default
cache is used.