In Django, is it possible to define a dynamically calculated setting based in another?
Question: (Maybe this question is more about Python but Django is the context, so here
it goes)

Suppose you need a setting `FOO` whose value depends on the value of setting
`BAR` (simplest case is make `CELERY_RESULT_BACKEND` equal to `BROKER_URL`).

If you have only one settings file, that's simple to achieve:

    
    
    BAR = some_value
    FOO = some_function(BAR)
    

However, it's quite popular to have many settings files, one for each
environment (e.g. production, development, test, stage, etc), as proposed in
the [project layout](https://github.com/twoscoops/django-twoscoops-project)
from the book, "Two Scoops of Django: Best Practices for Django 1.5".

In that case there is a `settings.base` module, which is imported with all its
contents by `settings.dev`, `settings.prod`, etc, which add their own specific
values or override those defined in `settings.base`.

The problem happens when I want to override `BAR` in some of those modules,
but I have to remember to recalculate `FOO` every time after that override.
That's error prone and not DRY.

A lambda function won't work because that setting would be a callable, not the
resulting value. Built-in function/decorator
[`property`](http://docs.python.org/2/library/functions.html#property) would
be ideal but it can only be used within classes (new-style). I don't know
anything else like that.

Ideas?


Answer: Yes, it is, the settings file is just a python script as well.

Most people do it already to build the Template Path setting.

[Django template Path](http://stackoverflow.com/questions/3038459/django-
template-path)

Now let's imagine this:

    
    
    ref = {
        'dev':  'FOO',
        'qa':   'BAR'
        'prod': 'BAZ'
    }
    
    ENV = 'PROD'  # Can also be DEV or QA
    
    DYNAMIC_SETTING = ref.get(ENV.lower(), None)  # => 'BAZ'
    

