开发者

Django - Haystack Query Serialization

开发者 https://www.devze.com 2023-01-29 17:18 出处:网络
I\'m trying to serialize a HayStack SearchQuerySet: from django.core import serializers serializers.serialize(\"开发者_StackOverflow中文版json\", SearchQuerySet().filter(content=request.GET[\'q\']))

I'm trying to serialize a HayStack SearchQuerySet:

from django.core import serializers
serializers.serialize("开发者_StackOverflow中文版json", SearchQuerySet().filter(content=request.GET['q']))

but it throws:

'SearchQuery' object has no attribute '_build_query'

How can I fix this?


I don't recommend call 'object' per result as it would hit to database and beat purpose of search performance. Instead consider calling get_stored_fields method which can be used with json dumps:

import simplejson as json
data = map(lambda x: x.get_stored_fields(), search_result)
json.dumps(data)


I had faced a similar problem. used something like this and it worked:

serializers.serialize("json", [x.object for x in queryset]

0

精彩评论

暂无评论...
验证码 换一张
取 消