Simple django reusable application for storing project settings in database.
Project description
Current version: 1.3-1 beta
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.
API
IMPORTANT: changed in version 1.3, old api still works but caching do not work with it.
import django_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 cached
django_settings.get('post_limit')
# if you not sure value exists you can pass "default" parameter,
# at this point default is NOT cached
django_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 method
django_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 exists
django_settings.exists('admin_email')
Installation & setup
Install it using pip:
$> pip install django-settings
Add “django_settings” to your INSTALLED_APPS
INSTALLED_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.py
from django.db import models
# ... your application models
import django_settings
class Text(django_settings.db.Model):
value = models.TextField()
class Meta:
abstract = True # it's IMPORTANT - it need to be abstract
django_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'),
}
Settings types
Builidin settings types: Email, Integer, String, PositiveInteger
Admin
You can manipulate setting via your admin interface.
Changelog
1.3 beta - several improvements has been made since ver 1.0
setting name need to be unique now (backward incompatiblity)
from now you can extend settings with your own types using django_settings.register function
new api with caching mechanism introduced
admin interface has been improved, action to clear cache keys only used by the package added
Some tests has been added for core functionality.
Backward incompatible changes
django_settings.models.Setting name need to be unique now, however ver 1.3 still allows it to not to be unique. Just set DJANGO_SETTINGS_UNIQUE_NAMES application setting to False (True is by default).
Contributors
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-settings-1.3-1-beta.tar.gz
.
File metadata
- Download URL: django-settings-1.3-1-beta.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9ece87b290e80aa779e45222e238ee1c5d70a9e401b2d3e3a1ac53c910ffa23 |
|
MD5 | 7e1e8990c9c0c7f32572f7fe6368d9a8 |
|
BLAKE2b-256 | d213726345cbf62b7f852cc1e74311187a767d9fdb039e1b55bbb2bfb3716428 |