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 toview(request, mess_id, format=None): """ Retrieve, update or delete a code snippet. """ try: # user1=user.objects.get(user_id=user_id) cancels = cancel_model.objects.filter(mess_id=mess_id) except cancel_model.DoesNotExist: return Response(status=status.HTTP_404_NOT_FOUND) if request.method == 'GET': serializer = CancelSerializer(cancels,many=True) return Response(serializer.data)
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)