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
...
非学,无以致疑;非问,无以广识