Exemplo n.º 1
0
    def put(self, request, pk, format=None):
        todo = get_object_or_404(ToDo, pk=pk)
        serializer = ToDoSerializer(todo, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
def list_create_todos(request):

    if request.method == "GET":
        ToDos = ToDo.objects.all()
        serializer = ToDoSerializer(ToDos, many=True)

        return Response(serializer.data)

    elif request.method == "POST":
        serializer = ToDoSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)