model_name = "MyModel"
model_name.objects.filter()
AttributeError: 'str' object has no attribute 'objects'
我怎样才能做到这一点,我已经尝试过:
exec(model_name)
input(model_name)
[model_name]
我知道有一种可能的方法,您可以使用
apps.get_model(model_name="string")
导入模型,但我不想使用这种方法,因为模型已经预先导入。有什么不同的方法可以将 model_name (字符串类型)转换为可以插入的类型 INSERTHERE.objects.filter()