Django - Haystack table request session

I am trying to serialize HayStack SearchQuerySet :

 from django.core import serializers serializers.serialize("json", SearchQuerySet().filter(content=request.GET['q'])) 

but he throws:

SearchQuery object does not have _build_query 'attribute

How can i fix this?

+7
json python django serialization django-haystack
source share
2 answers

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

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

+6
source share

I do not recommend calling an β€œobject” for each result, as it gets into the database and beats the search target. Instead, consider the 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) 
+6
source share

All Articles