(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 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
would be ideal but it can only be used within classes (new-style). I don't know anything else like that.
Ideas?