def createTask(request): data = JSONParser().parse(request) taskSerializer = TaskSerializer(data=data) if taskSerializer.is_valid(): taskSerializer.save() return JsonResponse(taskSerializer.data, status=201) return JsonResponse(taskSerializer.errors, status=400)
def post_task(request): data = JSONParser().parse(request) serializer = TaskSerializer(data=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)
def adicionar(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_404_BAD_REQUEST)
def create_task(request): if request.method == 'POST': data = JSONParser().parse(request) serializer = TaskSerializer(data=data) if serializer.is_valid(): serializer.save() return JsonResponse(serializer.data, status=201) return JsonResponse(serializer.errors, status=400)
def create_task(request): request_data = JSONParser().parse(request) task = TaskSerializer(data=request_data) if task.is_valid(): task.save() return JsonResponse(task.data, safe=False, status=201) else: return JsonResponse(task.errors, safe=False, status=400)
def createTask(request): print(request) infoJson = JSONParser().parse(request) print(infoJson) serializer_class = TaskSerializer(data=infoJson) if serializer_class.is_valid(): serializer_class.save() return JsonResponse(serializer_class.data, status=201) return JsonResponse(serializer_class.errors, status=400)
def atualizar(request, pk): try: task = Task.objects.get(pk=pk) except Task.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) serializer = TaskSerializer(task, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post_task(request): if request.method == "POST": data = JSONParser().parse(request) serializer = TaskSerializer(data=data) status = 404 if serializer.is_valid(): serializer.save() status = 200 return JsonResponse(serializer.errors, status=status)