goods/views.py
1.流程就是 从数据库中查找数据 并且找到对应的字段 之后对满足条件的数据进行过虑

冗余 复杂
上面代码的缺点就是查找参数并且判断是否存在 按照指定规则来进行排序
2.解决办法就是使用drf 的filter DjangoFilterbackend



3.模糊查询 自定义filter.py 对数据库数据实现某个条件的过滤



4.对数据进行过滤 模糊查询的search / order 排序


排序查找数据展示
filter_backends = (DjangoFilterBackend,filters.SearchFilter,filters.OrderingFilter)
filter_class=GoodsFilter
正则表达式来查找数据 ^ v以什么开头 = 精确查找 @全文搜索 $正则表达式
filter_fields=('=name','goods_brief','goods_desc')
排序 ordering根据什么字段和条件排序
ordering_fields=('sold_num','add_time)
网友评论