Package: django-settings
Django reusable application for storing global project settings in database.By project settings I mean things like admin mail, some default values like
default_post_limit etc. Values are validated depending their type.
Begining with ver 1.3 you can register your own settings values.Supported versionsPython: 2.6, 2.7  (python 2.6 requires importlib)Django: 1.3, 1.4, 1.5APIIMPORTANT: changed in version 1.3, old api still works but caching do not work with it.importdjango_settings# getting values# this will raise django_settings.models.Setting.DoesNotExist# exception if value not exists# if value is not in cache it will be cacheddjango_settings.get('post_limit')# if you not sure value exists you can pass "default" parameter,# at this point default is NOT cacheddjango_settings.get('post_limit',default=10)# set values - cache is updated for "get" and "exists" method# values are validated using setting_value model clean_fields methoddjango_settings.set('Email','admin_email','admin@admin.com')# If you want to avoid validation, do this:django_settings.set('Email','admin_email','admin@admin.com',validate=False)# checking if value existsdjango_settings.exists('admin_email')# getting all values as a dictdjango_settings.all()Installation & setupInstall it using pip:$>pipinstalldjango-settingsAdd “django_settings” to your INSTALLED_APPSINSTALLED_APPS=('django.contrib.contenttypes',# contenttypes framework is required# ...'django_settings',# ...)If you want to add your own settings models, please add them in one of your
applications models file, and register them with django_settings api:# <project>/<app>/models.pyfromdjango.dbimportmodels# ... your application modelsimportdjango_settingsclassText(django_settings.db.Model):value=models.TextField()classMeta:abstract=True# it's IMPORTANT - it need to be abstractdjango_settings.register(Text)Remember to define model as abstract, this is important because of how django
treats model classes.There is ability to setup some defaults via project settings.py file.
Those settings will be setup ONLY if they not already exists in db.DJANGO_SETTINGS={'application_limit':('Integer',2),'admin_email':('String','admin@mail.com'),}For import DJANGO_SETTINGS into database use command:./manage.pysettings_initializeDefault django-settings timeout is set to 1 day, but it can be changed
in your project settings:DJANGO_SETTINGS_TIMEOUT=60*60*10# 10 hoursTimeout let’s you define cache timeout (in sec.) for each of the
settings. After the given time values gets expired and each of them
will be recalculated (at the moment you ask for the given
setting). Introduced due to django’s defaults cache timeout (5 min):https://docs.djangoproject.com/en/dev/topics/cache/#cache-argumentsSettings typesBuilidin settings types: Email, Integer, String, PositiveIntegerAdminYou can manipulate setting via your admin interface.Changelog1.3.12 - post sync db settings initialization fixedinitial signal moved to models1.3-11 - several bug fixes“Clear cache for settings” admin action exception fixed [#12]admin setting edition cache update bug fixed“syncdb” signal callback is now fixed so it won’t “reinit” settings on every syncdb [#14]1.3-8 - DJANGO_SETTINGS_TIMEOUT fixit’s now cofigurable through project settings1.3-7 - several improvements and bug fix“all” function addedadmin setting add/edit callback: “DataAPI._set_cache_for” bug fix.settings timeout customization added (default to 1 day)1.3-4 - setup.py bug fix1.3-3 beta - python & django various versions compatibility changes1.3-2 beta - several bug fixes including cache unicode keys handling, tests added1.3-1 beta - admin render_change_form fix1.3 beta - several improvements has been made since ver 1.0setting name need to be unique now (backward incompatiblity)from now you can extend settings with your own types usingdjango_settings.registerfunctionnew api with caching mechanism introducedadmin interface has been improved, action to clear cache
keys only used by the package addedSome tests has been added for core functionality.Backward incompatible changesdjango_settings.models.Settingname need to be unique now, however
ver 1.3 still allows it to not to be unique. Just setDJANGO_SETTINGS_UNIQUE_NAMESapplication setting to False (True is by default).AuthorKuba Janoszek (kuba.janoszek@gmail.com)ContributorsTrey Hunnerygneobsavelevakolpakov