orm中的锁与事务
一、锁
1、行级锁
select * from table where...LOCK IN SHARE MODE查询添加共享锁
select * from table where ... FOR UPDATE查询时添加排他锁
添加表锁
lock table app01_publish write;
取消表锁
unlock table;
ORM中添加互斥锁
object.objects.select_fo_update().filter(author=request.user)
二、事务
方式一
from django.db import transaction
@transaction.atomic
def viewfunc(request):
db_stuff()
方式二
def viewfunc(request):
with transaction.atomic():
do_other_stuff()
do_other_stuff()

浙公网安备 33010602011771号