使用键值对更新 peewee 中的模型?

Using key, value pairs to update Models in peewee?

有没有一种方法可以在 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' 的值,而不是按字面解释它?

你能试试吗:

self.physician.update({key:value}).execute()

把它放在字典中可能就可以了,你也可以这样做

self.physician.update(kwargs).execute()

因为 kwargs 也是一个 dict 但当然你仍然需要首先删除 None 的值