def task_list(request): if request.method == 'GET': categories = TaskList.objects.all() serializer = TaskListSerializer2(categories, many=True) return Response(serializer.data) elif request.method == 'POST': serializer = TaskListSerializer2(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 task_list(request): if request.method == 'GET': categories = TaskList.objects.all() serializer = TaskListSerializer2(categories, many=True) return JsonResponse(serializer.data, safe=False) elif request.method == 'POST': body = json.loads(request.body) serializer = TaskListSerializer2(data=body) if serializer.is_valid(): # create function from serializer serializer.save() return JsonResponse(serializer.data) return JsonResponse(serializer.errors) return JsonResponse({'error': 'bad request'})
def post(self, request): serializer = TaskListSerializer2(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 put(self, request, pk): taskList = self.get_object(pk) serializer = TaskListSerializer2(instance=taskList, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def task_list_detail(request, pk): try: category = TaskList.objects.get(id=pk) except TaskList.DoesNotExist as e: return Response({'error': f'{e}'}, status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = TaskListSerializer2(category) return Response(serializer.data) elif request.method == 'PUT': serializer = TaskListSerializer2(instance=category, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_500_INTERNAL_SERVER_ERROR) elif request.method == 'DELETE': category.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def get(self, request, pk): taskList = self.get_object(pk) serializer = TaskListSerializer2(taskList) return Response(serializer.data)
def get(self, request): taskList = TaskList.objects.all() serializer = TaskListSerializer2(taskList, many=True) return Response(serializer.data)
def get(self, request): categories = TaskList.objects.all() serializer = TaskListSerializer2(categories, many=True) return Response(serializer.data)
def get(self, request, pk): category = self.get_object(pk) serializer = TaskListSerializer2(category) return Response(serializer.data)