Package: django-app-parameter
Django-app-parameterApp-Parameter is a very simple Django app to save some application's parameters in the database. Those parameters can be updated by users at run time (no need to new deployment or any restart). It can be used to store the website's title or default e-mail expeditor...Installpip install django-app-parameterSettingsAdd "django_app_parameter" to your INSTALLED_APPS setting like this:INSTALLED_APPS=[..."django_app_parameter",]If you want global parameters to be available in templates, set provided context processor:TEMPLATES=[..."OPTIONS":{"context_processors":[..."django_app_parameter.context_processors.add_global_parameter_context",],},]Runpython manage.py migrateto create the django_app_parameter's table.Start development server and visithttp://127.0.0.1:8000/admin/to create parameters (you'll need the Admin app enabled).UsageAdd new parametersUse admin interface to add parameters. You can access a parameter in your code use the "slug" field. Slug is built at first save with:slugify(self.name).upper().replace("-", "_").Examples:self.name     ==> self.slug
blog title    ==> BLOG_TITLE
sender e-mail ==> SENDER_E_MAIL
##weird@Na_me ==> WERIDNA_MESeeDjango's slugify functionfor more informations.Access parameter in python codeYou can read parameter anywhere in your code:fromdjango.views.genericimportTemplateViewfromdjango_app_parameterimportapp_parameterclassRandomView(TemplateView):defget_context_data(self,**kwargs):kwargs.update({"blog_title":app_parameter.BLOG_TITLE})returnsuper().get_context_data(**kwargs)In case you try to read a non existent parameter, an ImproperlyConfigured exception is raised.Access parameter in templatesYou can also access "global" parameters from every templates:<head><title>{{ BLOG_TITLE }}</title></head>A to make a parameter global, you only need to check is_global in admin.Bulk load parameter with management commandA management command is provided to let you easily load new parameters:load_param.It will create or update, the key for matching is the SLUG.It accepts 3 parameters: file, json and no-update.Option --fileAdd all parameters listed in the provided file.load_param --file /path/to/json.fileExample of file content:[{"name":"hello ze world","value":"yes","description":"123","is_global":true},{"slug":"A8B8C","name":"back on test","value":"yes","value_type":"INT"}]Here all available property you can add to the json:nameslugvalue_typevaluedescriptionis_globalIf slug is not provided it will be built. Default value_type is STR (string) and default is_global is False. Name is always required, others properties are optionnals.Option --jsonAdd parameters in one shot.load_param --json "[{'name': 'param1'}, {'name': 'param2'},]"The provided json needs to match same rules as for --file option above.You can't use --json and --file together.Option --no-updateThis option is provided to disable 'update' if parameter with same SLUG already exists. It can be used with --json and --file. It's useful to ensure all parameters are created in all environments and can be executed altogether with migrate. It avoid replacing already existing parameters' values which could lead to breaking environments.load_param --no-update --file required_parameters.jsonI use it in my starting container script:#!/bin/bash# Execute migrationspythonmanage.pymigrate# load new parameters if anypythonmanage.pyload_param--no-update--filerequired_parameters.json# launch webservergunicornconfig.wsgiEnjoy.Ideas which could come later (or not)A migration process to keep a list of your parameters in a file and automatically add them in each environmentShortcut to use Parameter.str(slug) (skip 'objects' key word)Management command to add a new parameter[] Check correctness of value type on save[] modifications historyBoolean type[] Datetime typesIf you have new idea you would like to see, feel free to open a new issue in this repo.Help developpingIf you want to participate to the development, there are (only) 2 constraints:Format all your code with blackAll unit test must pass and new code must be coveredBecause tests require a whole django environment, to run them I usehttps://github.com/Swannbm/runtest_on_dj_packages; if you know a better way to do it I am all ears :DWhy Django-App-ParameterBecause I wanted to try packaging a Django app and I used this one in most of my projects so it seemed a good idea.