예제 #1
0
 def post(self, request,pk, format=None):
     task = get_object(self,pk)
     serializer = TaskSerializer(task,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)
예제 #2
0
 def post(self, request):
     """ Adding a new task. """
     serializer = TaskSerializer(data=request.DATA)
     if not serializer.is_valid():
         return Response(serializer.errors, status=
             status.HTTP_400_BAD_REQUEST)
     else:
         data = serializer.data
         owner = request.user
         t = Task(owner=owner,description=data['description'], done=False,due_date=data['due_date'])
         t.save()
         request.DATA['id'] = t.pk # return id
         return Response(data, status=status.HTTP_201_CREATED)