示例#1
0
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)
示例#2
0
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'})
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
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)
示例#6
0
 def get(self, request, pk):
     taskList = self.get_object(pk)
     serializer = TaskListSerializer2(taskList)
     return Response(serializer.data)
示例#7
0
 def get(self, request):
     taskList = TaskList.objects.all()
     serializer = TaskListSerializer2(taskList, many=True)
     return Response(serializer.data)
示例#8
0
 def get(self, request):
     categories = TaskList.objects.all()
     serializer = TaskListSerializer2(categories, many=True)
     return Response(serializer.data)
示例#9
0
 def get(self, request, pk):
     category = self.get_object(pk)
     serializer = TaskListSerializer2(category)
     return Response(serializer.data)