Django app allowing users to set app specific preferences through the admin interface.
Project description
Django Preferences
Django app allowing users to set app specific preferences through the admin interface.
Provides singleton admin views for Preferences objects and a simple interface to preference values. Singleton views ensure only one preference intance per site is available for each Preferences class.
Installation
Install or add django-preferences to your Python path.
Add preferences to your INSTALLED APPS setting.
Add django.contrib.sites to your INSTALLED APPS setting. django-preferences associates preferences to specific sites and thus requires Django’s “sites” framework to be installed.
Optionally, add preferences.context_processors.preferences_cp to your TEMPLATE_CONTEXT_PROCESSORS settings. This will automatically add a preferences variable to your template context if you use RequestContext to create your context (see Usage below), i.e.:
TEMPLATE_CONTEXT_PROCESSORS = ( ...other context processors..., "preferences.context_processors.preferences_cp", )
Usage
To create preferences for your app create a Django ORM model as usual, with the model inheriting from preferences.models.Preferences. Also specify preferences.models as your model’s module:
from django.db import models from preferences.models import Preferences class MyPreferences(Preferences): __module__ = 'preferences.models' portal_contact_email = models.EmailField()
Admin classes are specified as per usual, except that they have to inherit from or be registered with preferences.admin.PreferencesAdmin, i.e.:
from django.contrib import admin from preferences.admin import PreferencesAdmin from <my_app>.models import MyPreferences admin.site.register(MyPreferences, PreferencesAdmin)
When your model is registered with admin it will show up under the Preferences app label in Django admin.
Preferences can be accessed in Python by importing the preferences module and traversing to your required preference in the form preferences.<ModelName>.<field>, i.e.:
from preferences import preferences portal_contact_email = preferences.MyPreferences.portal_contact_email
If you’ve specified the preferences.context_processors.preferences_cp as a TEMPLATE_CONTEXT_PROCESSORS you can similarly access your preferences within templates through the preferences variable, i.e.:
{{ preferences.MyPreferences.portal_contact_email }}
Changelog
0.1
Cleanup and fixing of tests courtesy of senyor.
Rewrite distinct query so it works with Oracle backend.
0.0.6
Better packaging.
0.0.5 (2011-08-17)
Added sites support.
Added unittests.
0.0.4 (2011-08-11)
Cleanup. Docs polish.
0.0.3
Spelling correction, thanks tiktuk.
0.0.2
Doc update to indicate importance of placing url include before admin url include.
0.0.1
First super alpha release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_preferences-0.1-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76eec15e5240e7e899e1a6491da22903ea7636fb05f5c9dad39d8197d010b720 |
|
MD5 | f36d23730c26d8b2fa39cff3cbf63249 |
|
BLAKE2b-256 | 85fde5e585c279baca595ae8cd644e14df7076f200ef3c547204e2ade2ba2ced |