源代码:
# 更新数据库
# 手动防重
project_exist = Project.objects.filter(name=data["name"]).exclude(id=data["project_id"])
if len(project_exist):
return JsonResponse(code=999992, msg="same name already exist",data={"name":data["name"]})
else:
# 从json中获取新的project
project_update = ProjectDeserializer(data=data)
# 事务操作, 在代码块内都是属于当前事务
with transaction.atomic():
if project_update.is_valid():
project_update.update(instance=project_object, validated_data=data)
# 记录当前动态
record_project_dynamic(project=data["project_id"],
operation="更新",
operationObject="项目",
user=request.user.pk,