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過濾、搜索、排序

文章插圖

推薦閱讀