예제 #1
0
    def get(self, request, *args, **kwargs):
        '''
        获取所有专题课信息
        :param request:
        :param args:
        :param kwargs:
        :return:
        '''
        # ret = {'code':1000,'data':None,'error':None}
        # 将字典封装成一个类,用ret.属性名去调用,简化代码
        ret = BaseResponse()
        try:
            queryset = models.Course.objects.all()
            # 分页
            page = PageNumberPagination()
            course_list = page.paginate_queryset(queryset, request, self)
            # 分页之后的结果序列化
            # ser = CourseSerializer(course_list,many=True)
            ser = CourseModelSerializer(course_list, many=True)
            # ret['data'] = ser.data
            ret.data = ser.data

        except Exception as e:
            # ret['code'] = 500
            ret.code = 500
            # ret['error'] = '获取数据失败'
            ret.error = '获取数据失败'

        return Response(ret.dict)
예제 #2
0
 def get(self, request, pk, *args, **kwargs):
     response = {'code': 1000, 'data': None, 'error': None}
     try:
         course = models.Course.objects.get(id=pk)
         ser = CourseModelSerializer(instance=course)
         response['data'] = ser.data
     except Exception as e:
         response['code'] = 500
         response['error'] = '获取数据失败'
     return Response(response)
예제 #3
0
파일: course.py 프로젝트: KhdaJhin/J
 def get(self, request, pk, *args, **kwargs):
     ret = BaseResponse()
     try:
         course = models.Course.objects.get(id=pk)
         ser = CourseModelSerializer(instance=course)
         ret.data = ser.data
     except Exception as e:
         print(e)
         ret.get_error()
     return Response(ret.dict)
예제 #4
0
 def get(self, request, pk, *args, **kwargs):
     ret = BaseResponse()
     try:
         course = models.Course.objects.filter(id=pk).first()
         ser = CourseModelSerializer(course)
         ret.data = ser.data
     except Exception as e:
         ret.code = 500
         ret.error = '获取数据失败'
     return Response(ret.dict)
예제 #5
0
 def get(self, request, pk, *args, **kwargs):
     ret = BaseResponse()
     try:
         course_data = models.DegreeCourse.objects.filter(pk=pk).first()
         ser = CourseModelSerializer(instance=course_data)
         ret.data = ser.data
     except Exception as e:
         ret.code = 500
         ret.error = '獲取數據失敗'
     return Response(ret.dict)
예제 #6
0
    def list(self, request, *args, **kwargs):
        ret = BaseResponse()
        try:
            queryset = models.Course.objects.all()
            page = PageNumberPagination()
            course_list = page.paginate_queryset(queryset, request, self)
            ser = CourseModelSerializer(instance=course_list, many=True)

            ret.data = ser.data
        except Exception as e:
            ret.code = 500
            ret.error = '获取数据失败'
        return Response(ret.dict)
예제 #7
0
    def retrieve(self, request, pk, *args, **kwargs):
        ret = BaseReponse()

        try:

            course = models.Course.objects.get(id=pk)
            ser = CourseModelSerializer(instance=course)
            ret['data'] = ser.data

        except Exception as e:
            ret['code'] = 500
            ret['error'] = '获取数据失败'

        return Response(ret.dict)
    def get(self, request, *args, **kwargs):

        ret = BaseResponse()
        try:
            #get data from db
            queryset = models.Course.objects.all()
            #分页
            page = PageNumberPagination()
            course_list = page.paginate_queryset(queryset, request, self)
            #分页后的结果执行序列化
            ser = CourseModelSerializer(instance=course_list, many=True)

            ret.data = ser.data
        except Exception as e:
            ret.code = 500
            ret.error = 'failed to get data'
        return Response(ret.dict)
예제 #9
0
    def get(self, request, *args, **kwargs):
        # response = {'code':1000,'data':None,'error':None}
        ret = BaseResponse()
        try:
            # 从数据库获取数据
            queryset = models.Course.objects.all()

            # 分页
            page = PageNumberPagination()
            course_list = page.paginate_queryset(queryset, request, self)

            # 分页之后的结果执行序列化
            ser = CourseModelSerializer(instance=course_list, many=True)

            ret.data = ser.data
        except Exception as e:
            ret.code = 500
            ret.error = '获取数据失败'

        return Response(ret.dict)
예제 #10
0
    def list(self, request, *args, **kwargs):
        ret = BaseResponse()
        try:
            # 从数据库获取数据
            queryset = models.Course.objects.all()

            # 分页
            # page = PageNumberPagination()
            # course_list = page.paginate_queryset(queryset, request, self)
            # 分页之后的结果执行序列化
            # print("345354",course_list)
            ser = CourseModelSerializer(instance=queryset, many=True)
            print("45646")
            ret.data = ser.data
            print("%%%%%%")
        except Exception as e:
            ret.code = 500
            ret.error = "获取数据失败"
            print("qqqqqqqqq", e)
        return Response(ret.dict)
예제 #11
0
파일: course.py 프로젝트: KhdaJhin/J
    def get(self, request, *args, **kwargs):
        ret = BaseResponse()
        try:
            # 从数据库获取数据
            query_set = models.Course.objects.all()

            # 分页
            page = PageNumberPagination()
            course_list = page.paginate_queryset(query_set, request, self)

            # 分页后执行序列化
            ser = CourseModelSerializer(instance=course_list, many=True)

            # 展示所有专业课
            pro_cou = models.Course.objects.filter(degree_course__isnull=True)
            print(pro_cou)

            ret.data = ser.data
        except Exception as e:
            print(e)
            ret.get_error()
        return Response(ret.dict)
예제 #12
0
    def get(self, request, *args, **kwargs):
        response = {'code': 100, 'data': None, 'error': None}

        try:
            # 从数据库获取数据
            queryset = models.Course.objects.all()

            print(queryset)

            # 分页
            # page = PageNumberPagination()
            # course_list = page.paginate_queryset(queryset,request,self)

            # 分页之后的结果执行序列化
            ser = CourseModelSerializer(queryset, many=True)

            response['data'] = ser.data
        except Exception as e:
            response['code'] = 500
            response['error'] = '获取数据失败'

        return Response(response)
예제 #13
0
 def list(self, request, *args, **kwargs):
     course_list = models.Course.objects.all()
     ser = CourseModelSerializer(instance=course_list, many=True)
     return Response(ser.data)