Пример #1
0
    def put(self, request, *args, **kwargs):
        json_data = request.body

        #Converting Json data into Python Dictionary
        stream = io.BytesIO(json_data)
        python_data = JSONParser().parse(stream)

        id = python_data.get('id')
        emp = Employee.objects.get(id=id)

        # perform Deserialization
        #convert Python Dictionary into Database code
        employee_serializer = EmployeeSerializers(emp,
                                                  data=python_data,
                                                  partial=True)
        if employee_serializer.is_valid():
            employee_serializer.save()
            msg = {'msg': 'Resource Updated successfully'}
            json_data = JSONRenderer().render(msg)
            return HttpResponse(json_data, content_type='application/json')

        json_data = JSONRenderer().render(employee_serializer.errors)
        return HttpResponse(json_data,
                            content_type='application/json',
                            status=400)
Пример #2
0
 def post(self, request, *args, **kwargs):
     json_data = request.body
     stream = io.BytesIO(json_data)
     pdata = JSONParser().parse(stream)
     serializer = EmployeeSerializers(data=pdata)
     if serializer.is_valid():
         serializer.save()
         msg = {'msg': 'Record 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')
Пример #3
0
 def put(self, request, *args, **kwargs):
     json_data = request.body
     stream = io.BytesIO(json_data)
     pdata = JSONParser().parse(stream)
     id = pdata.get('id')
     emp = Employee.objects.get(id=id)
     serializer = EmployeeSerializers(emp, data=pdata, partial=True)
     if serializer.is_valid():
         serializer.save()
         msg = {'msg': 'Record Updated 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')
Пример #4
0
	def post(self,request,*args,**kwargs):
		json_data = request.body

		#Converting Json data into Python Dictionary
		stream = io.BytesIO(json_data)
		python_data = JSONParser().parse(stream)

		#converting Python Dictionary into database code
		employee_serializer = EmployeeSerializers(data = python_data)
		if employee_serializer.is_valid():
			employee_serializer.save()
			msg = {'msg':'Resource created successfully'}
			json_data = JSONRenderer().render(data = msg)
			return HttpResponse(json_data,content_type='application/json')
		
		json_data = JSONRenderer().render(employee_serializer.errors)
		return HttpResponse(json_data,content_type='application/json',status=400)