我想知道是否可以在干草堆搜索结果上应用tastypie过滤器。
虽然这有效:
http://127.0.0.1:8000/posts/api/v1/post/?的 created__lt = 2016年2月26日
这不是:
http://127.0.0.1:8000/posts/api/v1/post/search/?q=django的&安培; created__lt = 2016年2月26日
q 这是传递给haystack搜索的参数,但是被忽略了created__lt。
这是使用的get_search方法:
def get_search(self, request, **kwargs):
self.method_check(request, allowed=['get'])
self.is_authenticated(request)
self.throttle_check(request)
# Do the query.
sqs = SearchQuerySet()
query = request.GET.getlist("q")
if query:
query_dict = {}
for q in query:
try:
query_dict[q.split(':')[0]] = q.split(':')[1]
sqs = sqs.filter(**query_dict)
except IndexError:
sqs = sqs.filter(content=q)
paginator = self._meta.paginator_class(request.GET, sqs,
resource_uri=self.get_resource_uri(), limit=self._meta.limit,
max_limit=self._meta.max_limit,
collection_name=self._meta.collection_name)
to_be_serialized = paginator.page()
bundles = [self.build_bundle(obj=result.object, request=request) for result in to_be_serialized['objects']]
to_be_serialized['objects'] = [self.full_dehydrate(bundle) for bundle in bundles]
to_be_serialized = self.alter_list_data_to_serialize(request, to_be_serialized)
return self.create_response(request, to_be_serialized)