【发布时间】:2018-11-03 06:13:57
【问题描述】:
我想为我的模型编写一个自定义更新方法。 基本上,我想确保传递给此方法的字段是此模型中存在的字段。 我想出了这样的东西
def update(self,dict):
#Check if the fields in this data are present in this model
for key in data:
if not hasattr(self, key):
#This property is not present
data.pop(key)
self.update(data)
但是当我做这样的事情时
modelMyobject.objects.filter(xxxxx).update(**dict)
这个方法永远不会被调用。关于我可以做些什么来解决这个问题的任何建议?
【问题讨论】:
标签: python django django-models filter