title: Serialize Django Queryset to JSON for Celery before execution
body: <p>I am given a Queryset from an external library and - since Querysets are lazy - I'd like to serialize it to JSON <em>before</em> it is accessed, and thus executed, in the DB, so it may be executed in an asynchronous Celery task instead.</p>
  
  <p>My question is, is there a way of representing the essential elements of a Queryset as JSON so I don't have to use Pickle?</p>
  
  <p>I know I could get the raw query with <code>queryset.query</code>, but since I'd have to execute a raw query at the other end, I don't much like that idea.</p>
  
  <h2>Details</h2>
  
  <p>The specific use-case here is evaluating the Queryset in a task so the results can then be exported to a file and dumped on a server for later access.</p>
  
  <p>The result set can be quite large, so doing the export as part of a standard request/response cycle can often timeout.</p>
  
  <p>The request is generated from a Django Admin change view list filter. I've tried going back through the list filter code, but it seems like it just generates filter objects - not suitable for JSON serialization.</p>
  
  <p>I could look at the list filter query string and re-evaluate all of the keys into a Queryset filter, but many of the filters are <code>SimpleListFilter</code> classes that also just return filter objects, and don't reveal real Queryset filters in the URL. I'd need to recreate logic for these filters just to get a kwarg-style filter that can be JSON serialized.</p>