Example #1
0
 def post(self, request, format=None):
     s = HostFail_Serializer(data=request.data)
     if s.is_valid():  # 验证
         s.save()
         json_data = {'code': 200, 'msg': '数据添加成功'}
         json_data['data'] = s.data
         return Response(json_data, content_type="application/json")
         # return api_response.JsonResponse(s.data,code=status.HTTP_200_OK,msg='success')
     json_data = {'code': 500, 'msg': '数据添加失败,请检查数据格式'}
     return Response(json_data, content_type="application/json")
Example #2
0
    def put(self, request, format=None):
        try:
            data_id = request.data['id']
        except Exception as e:
            print(e)
            json_data = {'code': 500, 'msg': '数据有错误获取不到id'}
            return Response(json_data,status=500)
        else:
            DATA_MODEL = self.get_object(data_id)
            s = HostFail_Serializer(DATA_MODEL, data=request.data)

            if s.is_valid(raise_exception=True):
                s.save()
                json_data = {'code': 200, 'msg': '更新成功'}
                return Response(json_data)
            json_data = {'code': 500, 'msg': '更新失败'}
            return Response(json_data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Example #3
0
    def get(self, request, format=None):

            queryset = Host_fail.objects.filter(is_inhost__exact='False').all()

            ##########以下内容在数据展示列表中不需要修改
            pg = MyPageNumberPagination()  # 实例化分页类
            page_data = pg.paginate_queryset(queryset=queryset, request=request, view=self)  # 根据请求的页码数,对数据进行分页
            s = HostFail_Serializer(instance=page_data, many=True)  # 序列花这个分页数据
            next = pg.get_next_link()  # 获取下一页
            prev = pg.get_previous_link()  # 获取上页
            count = queryset.count()  # 获取数据总数
            json_data = {'code': 0, 'msg': 'success', 'count': count, 'next': next, 'prev': prev}
            json_data['data'] = s.data
            return Response(json_data)