Django Dynamic Setting is a Django app, designed to help you manage your project settings, storage settings in database, provided admin UI to manage there settings.
pip install git+https://github.com/cuongnb14/django-dynamic-setting@master#egg=django-dynamic-setting
Add to install app
INSTALLED_APPS = [
...
"dynamic_setting",
...
]
Run migrate
python3 manage.py migrate
Define setting in your code
# your_app/setting.py
from dynamic_setting.base.fields import IntegerSettingField, BooleanSettingField, CharSettingField
from dynamic_setting.base.settings import Settings
class BotSettings(Settings):
sell_enable = BooleanSettingField(default=1, description='enable sell action')
title = CharSettingField(default="hello", is_public=True)
version = CharSettingField(default=1, min_value=0, max_value=10, is_public=True)
class Meta:
name = 'bot'
# your_app/apps.py
from django.apps import AppConfig
from dynamic_setting.settings_registry import settings_registry
from .setting import BotSettings
class BotConfig(AppConfig):
name = "cg_bot.bot"
verbose_name = "Bots"
def ready(self):
settings_registry.register(BotSettings)
Init setting
python3 manage.py init_dynamic_setting
Use setting
setting = BotSettings()
print(setting.title)