46.drf过滤、搜索、排序( 二 )

#排序http://xxxx/api/user?ordering=username # 默认排序http://xxxx/api/user?ordering=-username #反向排序http://xxxx/api/user?ordering=username,age#多个字段进行排序指定默认的排序方式
class UserList(ListAPIView):filter_backends = (filters.OrderingFilter)# 指定后端ordering_filter = ('username',) # 指定可以排序的字段ordering = ('username') #默认初始用username排序

46.drf过滤、搜索、排序

文章插图

推荐阅读