django-configurations
django-configurations copied to clipboard
Easy way to set one VAR2 to be VAR1 when VAR2 not set via envvar
trafficstars
I would like to find a proper way to set one variable to be another by default. I originally tried to do it like this:
class Base(Configuration):
CITY_NAME = values.Value('Chicago')
CITY_NAME_SHORT = values.Value(CITY_NAME)
This didn't work for reasons that are obvious to me now :)
Anyhow, this is how I'm currently doing it, but it still strikes me as messy:
class Base(Configuration):
CITY_NAME = values.Value('Chicago')
CITY_NAME_SHORT = values.Value('Chicago')
@classmethod
def setup(cls):
default_city_short = cls.CITY_NAME_SHORT.value
super().setup()
if default_city_short == cls.CITY_NAME_SHORT:
cls.CITY_NAME_SHORT = cls.CITY_NAME
Any thoughts on a better way? As it stands, it's perhaps clearer to handle it outside django-configurations, and just use os.environ...
Thanks!
I have a similar issue in #217. It would be cool if we had this usage pattern fixed. The simplicity of Django's settings module (w/o configurations) still has its obvious advantages. :worried: