5.11.drf的搜索和排序

搜索

goods/views.py

from rest_framework import filters

class GoodsCategoryViewSet(ListModelMixin, GenericViewSet):
    """
    获取商品类型列表
    """
    filter_backends = (..., filters.SearchFilter)
    search_fields = ('=name',)

The search behavior may be restricted by prepending various characters to the search_fields.

For example:

search_fields = ['=username', '=email']

排序

Last updated