【发布时间】:2019-10-20 02:18:10
【问题描述】:
我使用 [https://www.npmjs.com/package/vue-bootstrap4-table#8-filtering][1] 和 django-rest-framework。
问题在于该组件使用完全不同的查询参数进行排序、过滤等。
vue-bootstrap4-table
http://127.0.0.1:8000/api/products/?queryParams=%7B%22sort%22:[],%22filters%22:[%7B%22type%22:%22simple%22,%22name%22:%22code%22,%22text%22:%22xxx%22%7D],%22global_search%22:%22%22,%22per_page%22:10,%22page%22:1%7D&page=1
"filters":[{"type":"simple","name":"code","text":"xxx"}],
而 Django-rest-framework 需要这种格式:
../?code__icontains=...
我想弄清楚如何让DRF 接受这种格式而不是内置格式?
我只使用ViewSet。
class ProductViewSet(viewsets.ModelViewSet):
serializer_class = ProductSerializer
filter_class = ProductFilter
filter_backends = [filters.OrderingFilter]
ordering_fields = '__all__'
有可能吗?
【问题讨论】:
标签: python django django-rest-framework