Esempio n. 1
0
 def put(self, request, pk):
     todo = self.get_object(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)
Esempio n. 2
0
 def post(self, request):
     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)
Esempio n. 3
0
def todo_list(request):
    if request.method == 'GET':
        todo = Todo.objects.all()
        serializer = TodoSerializer(todo, 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)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 4
0
def todo_detail_change_and_delete(request, pk):
    try:
        todo = Todo.objects.get(pk=pk)
    except Todo.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = TodoSerializer(todo)
        return Response(serializer.data)
    elif request.method == 'PUT':
        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)
    elif request.method == 'DELETE':
        todo.delete()
        return Response(status= status.HTTP_204_NO_CONTENT)
Esempio n. 5
0
 def get(self, request, pk):
     todo = self.get_object(pk)
     serializer = TodoSerializer(todo)
     return Response(serializer.data)
Esempio n. 6
0
 def get(self, request):
     todo = Todo.objects.all()
     serializer = TodoSerializer(todo, many=True)
     return Response(serializer.data)
Esempio n. 7
0
 def get(self, request, pk):
     serializer = TodoSerializer(todo)
     return Response(serializer.data)
Esempio n. 8
0
from app.models import Todo
from app.serializers import TodoSerializer

todo = Todo.objects.first()
serializer = TodoSerializer(todo)
serializer.data