Django
1.4+支持select_for_update,在早期版本中,您可以执行原始SQL查询,例如
select... for update,根据基础数据库,该行将锁定该行免受任何更新的影响,您可以对该行执行任何 *** 作,直到事务结束。例如
from django.db import [email protected]_manually()def add_points(request): user = User.objects.select_for_update().get(id=request.user.id) # you can go back at this point if something is not right if user.points > 1000: # too many points return user.points += calculate_points(user) user.save() transaction.commit()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)