def add(request, format=None): if request.method == 'POST': serializer =CancelSerializer(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) else: return Response( status=status.HTTP_400_BAD_REQUEST)
def appoint(request, cancel_id, format=None): """ Retrieve, update or delete a code snippet. """ try: cancels = cancel_model.objects.get(cancel_id=cancel_id) except cancel_model.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = CancelSerializer(cancels) return Response(serializer.data) elif request.method == 'PUT': serializer = CancelSerializer(cancels, data=request.data) if serializer.is_valid(): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': cancels.delete() return Response(status=status.HTTP_204_NO_CONTENT)