博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue_drf之多级过滤、排序、分页
阅读量:5842 次
发布时间:2019-06-18

本文共 3239 字,大约阅读时间需要 10 分钟。

  一、前端代码

  1,父组件free_course.vue

  父组件的css

View Code

  2,子组件filter.vue

  子组件的css

View Code

  二、后端代码

  settings.py配置

REST_FRAMEWORK = {    #过滤组件    'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',                                # 解决过滤组件和排序组件之间的覆盖问题                                'rest_framework.filters.OrderingFilter'),}

  views.py 

class StandardPageNumberPagination(PageNumberPagination):     page_size_query_param = 'page_size'     max_page_size = 1
class CourseView(ListAPIView):    queryset = Course.objects.filter(status=0,is_delete=False).order_by('orders')    serializer_class = CourseModelSeralizer    #设置过滤字段    filter_fields = ('course_category',)    #必须把这个删掉,它和后面的排序字段冲突    # filter_backends = [OrderingFilter]    ordering_fields = ('id', 'students', 'price')    pagination_class = StandardPageNumberPagination

  serializer.py

from rest_framework import serializersfrom .models import *class CourseClassifyModelSerializer(serializers.ModelSerializer):    class Meta:        model=CourseClassify        fields=('id','name',)class TeacherModelSerializer(serializers.ModelSerializer):    class Meta:        model=Teacher        fields=['name','role','image','brief']class CourseLessonModelSerializer(serializers.ModelSerializer):    class Meta:        model=CourseLesson        fields = [ 'name', 'section_link','duration','free_trail','orders']class CourseChapterModelSerializer(serializers.ModelSerializer):    coursesections=CourseLessonModelSerializer(many=True)    class Meta:        model=CourseChapter        fields=['chapter','name','coursesections']class PriceServicesModelSerializer(serializers.ModelSerializer):    """价格服务策略序列化器"""    class Meta:        model = PriceService        fields = ("condition","sale",'remaintime')class PriceServiceTypeModelSerializer(serializers.ModelSerializer):    """价格服务类型序列化器"""    priceservices = PriceServicesModelSerializer(many=True)    # priceservices 价格策略    class Meta:        model = PriceServiceType        fields = ("id","name","priceservices")class CourseModelSeralizer(serializers.ModelSerializer):    teacher=TeacherModelSerializer()    coursechapters=CourseChapterModelSerializer(many=True)    price_service_type=PriceServiceTypeModelSerializer()    class Meta:        model=Course        fields=['id','name','course_img','students','brief_url','levels','lessons','pub_lessons','price','teacher','coursechapters','price_service_type','current_price']

 

转载于:https://www.cnblogs.com/12345huangchun/p/10659638.html

你可能感兴趣的文章
内存中压缩图片
查看>>
Django学习笔记(4)
查看>>
Android命令Monkey压力测试,详解
查看>>
log4j2 mybatis 显示 sql 和 结果集
查看>>
Linux——JDK的部署
查看>>
设计模式-Factory Method Pattern
查看>>
VS2010下Boost1.55.0配置
查看>>
负载均衡(LB)集群 dr
查看>>
Entity Framework 批量插入
查看>>
hierarchyviewer
查看>>
linux 文件系统的管理 (硬盘)
查看>>
微服务框架开发(二)—扩展spring schema
查看>>
(转)直接拿来用!最火的iOS开源项目(一)
查看>>
java8新特性stream深入解析
查看>>
Linux manjaro系统安装后无法连接wifi,解决方案
查看>>
关于我的知识星球服务
查看>>
前端每隔几秒发送一个请求
查看>>
div+css+js 树形菜单
查看>>
javax.jdo.option.ConnectionURL配置的问题
查看>>
ubuntu 开启 apache mod_rewrite
查看>>