Example #1
0
 def put(self, request, pk, format=None):
     emp = self.get_object(pk)
     serializer = EmployeeSerializer(emp, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response({'msg': 'successfully updated'})
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Example #2
0
 def post(self,request,*args,**kwargs):
     json_data=request.body
     stream=io.BytesIO(json_data)
     pdata=JSONParser().parse(stream)
     serializer=EmployeeSerializer(data=pdata)
     if serializer.is_valid():
         serializer.save()
         msg={"msg":"resource created successfully"}
         json_data=JSONRenderer().render(msg)
         return HttpResponse(json_data,content_type="application/json")
     json_data=JSONRenderer().render(serializer.errors)
     return HttpResponse(json_data,content_type='application/json')
Example #3
0
 def put(self,request,*args,**kwargs):
     json_data=request.body
     stream=io.BytesIO(json_data)
     data=JSONParser().parse(stream)
     id=data.get('id')
     emp=Employee.objects.get(id=id)
     serializer=EmployeeSerializer(emp,data=data,partial=True)
     if serializer.is_valid():
         serializer.save()
         msg={'msg':'resource updataed successfully'}
         json_data=JSONRenderer().render(msg)
         return HttpResponse(json_data,content_type='application/json')
     json_data=JSONRenderer().render(serializer.error)
     return HttpResponse(json_data,content_type='application/json')
Example #4
0
 def get(self,request,*args,**kwargs):
     json_data=request.body
     stream=io.BytesIO(json_data)
     pdata=JSONParser().parse(stream)
     print(pdata)
     id=pdata.get('id',None)
     if id is not None:
         emp=Employee.objects.get(id=id)
         serialize=EmployeeSerializer(emp)
         json_data=JSONRenderer().render(serialize.data)
         return HttpResponse(json_data,content_type='application/json')
     qs=Employee.objects.all()
     serialize=EmployeeSerializer(qs,many=True)
     json_data=JSONRenderer().render(serialize.data)
     return HttpResponse(json_data,content_type='application/json')
Example #5
0
 def get(self, request, pk, format=None):
     qs = self.get_object(pk)
     serializer = EmployeeSerializer(qs)
     return Response(serializer.data)
Example #6
0
 def post(self, request, format=None):
     serializer = EmployeeSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_Created)
     return Response(serailizer.errors, status=status.HTTP_400_BAD_REQUEST)
Example #7
0
 def get(self, request, format=None):
     emp = Employee.objects.all()
     serializer = EmployeeSerializer(emp, many=True)
     return Response(serializer.data)