Exemple #1
0
    def post(self, request, version, format=None):
        serializer = RoomSerializer(data=request.data,
                                    context={'request': request})

        if serializer.is_valid():
            serializer.save()

            return Response(serializer.validated_data,
                            status=status.HTTP_201_CREATED)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #2
0
    def put(self, request, version, pk, format=None):
        room = get_object_or_404(Room, pk=pk)
        serializer = RoomSerializer(room,
                                    data=request.data,
                                    context={'request': request})

        if serializer.is_valid():
            serializer.save()

            return Response(serializer.validated_data,
                            status=status.HTTP_200_OK)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)