有没有办法在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”的值,而不是逐字解释它?
你能试试吗:
self.physician.update({key:value}).execute()
把它写进口述里可能会起到作用,你也可以
self.physician.update(kwargs).execute()
既然kwargs也是一个dict,但是当然,您仍然需要先删除那些不存在的值