Merge branch 'master' of github.com:comoga/django-constance

This commit is contained in:
Jannis Leidel 2013-04-12 16:50:53 +02:00
commit c91188a211
2 changed files with 10 additions and 8 deletions

View file

@ -122,6 +122,8 @@ you need to install this library, too. E.g.::
pip install django-picklefield
Alternatively follow the backend specific installation instructions above.
The database backend has the ability to automatically cache the config
values and clear them when saving. You need to set the following setting
to enable this feature::
@ -132,7 +134,7 @@ to enable this feature::
cross-process caching, because correct cache invalidation
can't be guaranteed.
Starting in Django 1.3 you can alternatively be the name of an entry of
Starting in Django 1.3 you can alternatively use the name of an entry of
the ``CACHES`` setting. E.g.::
CACHES = {
@ -173,11 +175,11 @@ Constance can be used from your Python code and from your Django templates.
To access the config object from your template, you can either
pass the object to the template context::
from django.shortcuts import render_to_response
from django.shortcuts import render
from constance import config
def myview(request):
return render_to_response('my_template.html', {'config': config})
return render(request, 'my_template.html', {'config': config})
Or you can use the included config context processor.::
@ -192,7 +194,7 @@ Constance can be used from your Python code and from your Django templates.
Then, in your template you can refer to the config values just as
any other variable, e.g.::
<h1>Welcome on {% config.SITE_NAME %}</h1>
<h1>Welcome on {{ config.SITE_NAME }}</h1>
{% if config.BETA_LAUNCHED %}
Woohoo! Head over <a href="/sekrit/">here</a> to use the beta.
{% else %}

View file

@ -37,10 +37,10 @@ class DatabaseBackend(Backend):
def mget(self, keys):
if not keys:
return
prefixed_keys = [self.add_prefix(key) for key in keys]
stored = self._model._default_manager.filter(key__in=prefixed_keys)
for key, const in itertools.izip(keys, stored):
yield key, const.value
keys = dict((self.add_prefix(key), key) for key in keys)
stored = self._model._default_manager.filter(key__in=keys.keys())
for const in stored:
yield keys[const.key], const.value
def get(self, key):
key = self.add_prefix(key)