def post(self, request, pk=None, format=None): """增加队伍""" serializer = TeamSerializer(data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): team = self.get_object(pk) serializer = TeamSerializer(team, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response({'error': serializer.errors}, status=status.HTTP_400_BAD_REQUEST)
def put(self, request, pk, format=None): """修改队伍""" team = get_object_or_404(Team, pk=pk) serializer = TeamSerializer(team, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)