ORM锁和事务

事务和锁

mysql:  中写法
select * from book where id=1 for update;

begin;  start transaction;
	select * from t1 where id=1 for update;
commit

rollback;


django orm中写法
models.Book.objects.select_for_update().filter(id=1)

事务

from django.db import transaction

@transaction.atomic
def index(request):
	
	...


def index(request):
	...
	with transaction.atomic():
		xxxx
	...

原文地址:https://www.cnblogs.com/saoqiang/p/12396970.html