Announcing django-constance

Posted on December 2, 2010

You know it well: your settings.MONTHLY_SALARY should have been a variable. There is an easy way out now:

from constance import config

...
    if config.MONTHLY_SALARY < advertised_job.salary:
        advertised_job.post_my_CV()

You can use the dynamic settings as it were static. Well almost. Sed/replace your code with config.MONTHLY_SALARY and include from constance import config there. You need to put a little into your settings.py; your original value of the constant may become the default value for the variable.

INSTALLED_APPS = (
    ...
    'constance',
)

CONSTANCE_CONNECTION = {
    'host': 'localhost',
    'port': 6379,
    'db': 0,
}


CONSTANCE_CONFIG = {
    'MONTHLY_SALARY': (9000, 'your monthly salary'),
}

Navigate to your admin and you will see constance appear among all your applications.

/static/resources/screenshot1.png

Enter Constance|Config to find and change the settings. The new value will be used immediately in your code at all places with config.MONTHLY_SALARY.

/static/resources/screenshot2.png

django-constance is a collaborative work of our team here at Comoga, Jannis Leidel, and you.

django-constance is rather a simple demonstration to try and create a Django application. We want to go public with a lot what we have done and this is to try all that is around going open source. We were caught by surprise to hear someone is actually using it. We hope you enjoy it!