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
. The problem is Im having this kind of error AttributeError: 'Person' object has no attribute 'update'
. It is necessary to use p.update
? to change the value from Yes
to 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.
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
Person.objects.filter(Q(paid = 'Yes')).update(paid="Paid")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.