[英]AttributeError: 'Person' object has no attribute 'update' Django
Im having a problem with this query.我有这个查询的问题。 All I want is to change the paid value if the paid is equals to Yes
then it must be change into Paid
and if paid is equals to No
then it is Unpaid
.我想要的只是更改已支付的值,如果已支付等于是,那么它必须更改为已Paid
,如果已支付等于Yes
,则它是No
Unpaid
的。 The problem is Im having this kind of error AttributeError: 'Person' object has no attribute 'update'
.问题是我有这种错误AttributeError: 'Person' object has no attribute 'update'
。 It is necessary to use p.update
?有必要使用p.update
吗? to change the value from Yes
to Paid
?将值从Yes
更改为Paid
?
This is what I've been trying这是我一直在尝试的
for p in Person.objects.filter(Q(paid = 'Yes')):
p.update(paid="Paid")
You can either save each object.您可以保存每个 object。
for p in Person.objects.filter(Q(paid = 'Yes')):
p.paid = "Paid"
p.save()
OR或者
update
method is available on QuerySet
, hence you can use update
方法在QuerySet
上可用,因此您可以使用
Person.objects.filter(Q(paid = 'Yes')).update(paid="Paid")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.