我正在为我的模型编写配置词典。我需要访问现在正在配置模型下面声明的转发模型声明。例如
class FirstModel(models.Model):
TYPE_MODEL = {
'type1': SecondModel,
'type2': ThirdModel
}
some_field = models.CharField(
choices=(
('type1', 'type 1 display'),
('type2', 'type 2 display')
)
)
def do_some_with_config(self):
model = self.TYPE_MODEL.get(self.some_field)
... do something with model ...
class SecondModel(models.Model):
... its own fields ...
class ThirdModel(models.Model):
... its own fields ...
这里有没有比将第一模型移到ThirdModel下方更好的方法,或者在模型中配置这些dicts一般是个好主意?