view.py的小得示例
def update_person(request):
try:
p = person.objects.filter(id__gt=23)
# p.update(age=233) # 批量更新
# pf = p.first()
# if pf:
# pf.name = '刘果'
# pf.save()
# print(p.first())
# else:
# return HttpResponse('没找到')
p = person.objects.filter(id__gt=23).first()
p.age = 999
p.save(update_fields=['age'])
except Exception as e:
return HttpResponse('修改失败')
return HttpResponse('修改成功')
|