标签:self _id bsp objects port res item erro mod
django 要加锁 必须先加事物
例子
from rest_framework import exceptions
from django.db import transaction
def perform_create(self, serializer): with transaction.atomic(): price = self.request.data.get(‘price‘) item_id = self.request.data.get(‘item‘) result = models.BidRecord.objects.filter(item_id=item_id).aggregate(max_price=Max(‘price‘)).select_for_update() max_price = result[‘max_price‘] if price > max_price: serializer.save(user=self.request.user) raise exceptions.ValidationError(‘已经被出价了,再涨涨.‘)
标签:self _id bsp objects port res item erro mod
原文地址:https://www.cnblogs.com/a438842265/p/12514565.html