Django:获取具有动态变量名和值的模型实例

2024-09-30 01:21:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下错误:Cannot resolve keyword 'attrName1' into field. Choices are: codesectrepmodel, configCons, id。我的代码:

modelName1="ConfigConsModel"
model1 = get_model('actsInformationRetrieval', modelName1)
print "model attr", model1._meta.get_all_field_names() #displays ['codesectrepmodel', 'configCons', 'id']
print "attrName1", attrName1 #displays configCons
print "attr1", attr1 #displays ECOFIN
attr1Instance=model1.objects.get(attrName1=attr1)

怎么了? 我认为问题在于get_model返回的是模型类,而不是对象。正确的?在


Tags: idfieldgetmodel错误resolveprintmodel1

热门问题