Beispiel #1
0
 def put(self, request, pk, format=None):
     quote = self.get_object(pk)
     serializer = QuoteSerializer(quote, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
 def post(self, request, format=None):
     print("Create quote called")
     serializer = QuoteSerializer(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)
 def post(self, request, *args, **kwargs):
     quotes_all_obj = QuoteSerializer(data=request.data)
     if quotes_all_obj.is_valid():
         new_obj = quotes_all_obj.save()
         new_ser_obj = QuoteSerializer(new_obj)
         return Response(new_ser_obj.data)
     else:
         return Response(new_ser_obj.errors)
 def put(self, request, id, *args, **kwargs):
     quote_obj = Quotes.objects.get(id=id)
     quote_ser_obj = QuoteSerializer(instance=quote_obj,
                                     data=request.data,
                                     partial=True)
     if quote_ser_obj.is_valid():
         updated_obj = quote_ser_obj.save()
         updated_ser_obj = QuoteSerializer(updated_obj)
         return Response(updated_ser_obj.data)
     else:
         return Response(updated_ser_obj.errors)