有没有一种方法可以使用peewee中的键,值对以编程方式更新模型?我一直在尝试通过使用以下代码遍历** kwargs来做到这一点:
for key, value in kwargs.items():
if value is not None:
self.physician.update(key=value)
但这给了我以下错误:
AttributeError: type object 'RequestDetail' has no attribute 'key'
有什么方法可以使update()方法接受key参数作为'key'的值,而不是直接对其进行解释?
答案 0 :(得分:0)
您可以尝试:
self.physician.update({key:value}).execute()
将其放入字典中可能会达到目的,您也可以
self.physician.update(kwargs).execute()
由于kwargs也是字典,但您当然仍然需要删除“无优先”的值