def get(self,request,*args,**kwargs):
     try:
         get=newsReader.objects.all()
         serializer=newsReaderSerializers(get,many=True)
         return JsonResponse({"success":True,"data":serializer.data})
     except newsReader.DoesNotExist:
         raise Http404
Exemplo n.º 2
0
 def get(self, request, id, format=None):
     try:
         get=self.get_object(id)
         serializer=newsReaderSerializers(get)
         return JsonResponse({"success":True,"data":serializer.data})
     except Http404:
         return JsonResponse({"success":False,"message:":"NewsReader not found"})
 def post(self,request,format=None):
     try:
         serializer=newsReaderSerializers(data=request.data)
         if serializer.is_valid():
             serializer.save()
             return JsonResponse({"success":True,"data":serializer.data})
         return JsonResponse({"message":serializer.errors})
     except Http404:
         return Response({"success":False,"message":"news data not added"})
Exemplo n.º 4
0
 def put(self,request,id,format=None):
     try:
         obj=self.get_object(id)
         serializer=newsReaderSerializers(obj,data=request.data,partial=True)
         if serializer.is_valid():
             serializer.save()
             return JsonResponse({"success":True,"data":serializer.data})
         return JsonResponse({"message":serializer.errors})
     except Http404:
         return JsonResponse({"success":False,"message":"NewsReader data not updated"})