我有一个模型
#models.py
class BaseModel(model.Models)
some_field = ...
class Proxy_1(BaseModel)
class Meta:
proxy=True
class Proxy_2(BaseModel)
class Meta:
proxy=True
class Proxy_3(BaseModel)
class Meta:
proxy=True
在我看来
#views.py
#check the field and based on the value
#choose appropriate Proxy model
if request.POST['some_field'] == '1'
# Table_Name = Proxy_1 ??????? ---HERE ---
if request.POST['some_field'] == '2'
# Table_Name = Proxy_2 ??????? ---HERE ---
if request.POST['some_field'] == '3'
# Table_Name = Proxy_3 ??????? ---HERE ---
foo = Table_Name.objects.get_or_create(...)
我真的不知道该怎么做...显然我可以在 request.POST 调用之间编写 foo = Table_Name.objects.get_or_create(...) ,但是将来会太长且难以调试。
我的想法也是关于在 models.py 中创建一个函数来检查它,但又不知道该怎么做,或者可能以某种方式在我的 html 模板中检查它。
谢谢