0

In an effort to avoid from .local_settings import * and based on that post, I created a class-based settings file.

The idea is to have a Common class which is inherited from Dev or Prod class as such:

./my_project/settings.py:

import sys


settings_module = sys.modules[__name__]


class Common:
    SETTING1 = 'set'
    SETTING2 = 'set again'

    def __init__(self):
        for each in dir(self):
            if each.isupper():
                setattr(settings_module, each, getattr(self, each))


class Dev(Common):
    SETTING1 = 'set_dev'


class Prod(Common):
    SETTING1 = 'set_prod'


#initialize the chosen class
Prod()

Is it a good idea in terms of concurrency or any other "deep internal" issue in the long term?

Django imports the settings as a module and discourages any other use.

It seems to be working. I have created a gist with some settings that illustrates the idea.

raratiru
  • 6,295
  • 2
  • 52
  • 93

0 Answers0