【发布时间】:2016-02-21 10:31:36
【问题描述】:
我正在尝试创建一个 FilterSet,其过滤器设置为 MethodFilter 期望多个值:
过滤器.py
class MyFilter(django_filters.FilterSet):
first_filter = django_filters.MethodFilter()
class Meta:
model = myModel
fields = ['first_filter']
def filter_first_filter(self, queryset, value):
# I expect value to setup with an array of values
myquery = Q()
return queryset.filter(myquery)
Views.py
class MyView(RetrieveAPIView):
def get(self, request, format=None, **kwargs):
filter = MyFilter(request.query_params, queryset=myModel.objects.all())
# Other things go there using the filter instanciated
所以当我用这种 URL /my_view?first_filter=thing1&first_filter=thing2 请求视图时,只有 thing2 被传入方法 filter_first_filter 的值,而不是 ['thing1', 'thing2]。
如何改变这种行为?
【问题讨论】:
-
尝试像我对 pdb 包所做的那样进行调试
标签: django django-rest-framework django-filter