Note that there are some explanatory texts on larger screens.

plurals
  1. POReturning two things in one HttpResponse
    text
    copied!<p>I am trying to implement paging across ajax calls. The page should not refresh when the user wants to see the next x num of results.</p> <p>Here is my problem. Returning the QuerySet is super simple. I just do (sumaJson is custom)</p> <pre><code>data = serializers.serialize('sumaJson', result_page.object_list, relations=('first_major', 'country_of_origin', 'second_major')) return HttpResponse(data, mimetype="application/json") </code></pre> <p>Now I also want to return things like</p> <pre><code>result_page.has_previous() result_page.has_next() result_page.paginator.count </code></pre> <p>and so on. I for the life of me can't figure out how to get both across in one response. I can't add this info to result_page.object_list because then the serializer fails. If I something of the sort of </p> <pre><code>simplejson.dumps(paging_info + result_page.object_list) </code></pre> <p>Then in the javascript the QuerySet is no longer a list of objects but just a big string of characters which can't be interpreted with </p> <pre><code>$.each(data.data, function(index, item){ </code></pre> <p>I tried some bad hacks like creating a fake object and putting it in the object_list, serializing this and then deleting the object. This allows me to get the data across. However, I don't want to be creating and deleting fake objects.</p> <p>I don't want to meddle with the serializer. I don't want to send a second ajax request once I get the querySet back to get the paging info.</p> <p>Am I missing something? Is there an easy way to get both across in one response? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload