restframework 使用OrderingFilter实现排序
作者:互联网
导入
from rest_framework.filters import OrderingFilter
使用
class CourseListApiView(ListAPIView): # 指定过滤和排序类 filter_backends = [DjangoFilterBackend, OrderingFilter,] # 指定过滤字段 filter_fields = ('course_category',) # 指定排序字段 ordering_fields = ('id', 'students', 'price') queryset = Course.objects.filter(is_show=True).order_by('orders', '-id') serializer_class = CourseSerializer
测试
标签:fields,id,filter,restframework,OrderingFilter,排序,class 来源: https://www.cnblogs.com/wtil/p/14964998.html