gpt4 book ai didi

python - Django Python ...更新数据库中的多个元素

转载 作者:行者123 更新时间:2023-11-28 22:52:44 24 4
gpt4 key购买 nike

迎角, 我知道这个问题很愚蠢,但我被困在这里

这是代码...

nq = Notifications.objects.filter(userid__iexact=q)
for string in nq:
string.markType = "Read"
results = Notifications.objects.filter(Q(userid__iexact=q)).order_by('-id')

但是 markType 未能设置为“Read”...为什么?

最佳答案

您可能打算在更改后保存对象:

nq = Notifications.objects.filter(userid__iexact=q)
for string in nq:
string.markType = "Read"
string.save()
results = Notifications.objects.filter(Q(userid__iexact=q)).order_by('-id')

关于python - Django Python ...更新数据库中的多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20180667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com