def put(self, request, pk): task = self.get_object(pk) serializer = TaskSerializer(instance=task, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors)
def post(self, request): serializer = TaskSerializer(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_500_INTERNAL_SERVER_ERROR)
def post(self, request, pk): tasklist = self.get_object(pk) serializer = TaskSerializer(data=request.data) if serializer.is_valid(): serializer.save(task_list=tasklist) return Response(serializer.data) return Response(serializer.errors)
def get(self, request, pk): task = self.get_task(pk) serializer = TaskSerializer(task) return Response(serializer.data)
def get(self, request, pk): tasklist = self.get_object(pk) tasks = tasklist.tasks.all() serializer = TaskSerializer(tasks, many=True) return Response(serializer.data)
def get(self, request): tasks = Task.objects.all() serializer = TaskSerializer(tasks, many=True) return Response(serializer.data, status=status.HTTP_200_OK)