Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serialize a django-haystack queryset

I want to export the results I have in a Queryset that I obtain from a haystack search view. In order to do this, I've found the best way is by doing it asyncronally, so I'm using Celery and Rabbitmq to manage the task and there create the file and iterate over all the results and then notify the user via email that the file is ready for them to grab it. However, in order to pass Celery the QuerySet, I need to serialize it.

Is there a quick way to do this? Or should I copy the request parameters and redo the search?

like image 998
Julian Avatar asked Jun 23 '10 14:06

Julian


1 Answers

You can serialize the Haystack QuerySet to JSON like this:

from django.core import serializers
serializers.serialize("json", [q.object for q in queryset])
like image 187
Herman Schaaf Avatar answered Oct 31 '22 18:10

Herman Schaaf