title: Django pagination overhead with sorting
body: <p>I try to implement pagination structure in Django with some sort options however, I can't figure out how can I do that properly.</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def search(request):
      eList = Employer.objects.filter(eminence__lt=4).order_by('-eminence')
  
      paginator = Paginator(eList, 3) # Show 3 contacts per page
  
      page = request.GET.get('page')
      try:
          employerList = paginator.page(page)
      except PageNotAnInteger:
          employerList = paginator.page(1)
      except EmptyPage:
          employerList = paginator.page(paginator.num_pages)
  
  return render_response(request, 'employer/search.html', {'employerList':employerList})
  </code></pre>
  
  <p><strong>search.html</strong></p>
  
  <pre><code>&lt;div class="pagination"&gt;
      &lt;span class="step-links"&gt;
          {% if employerList.has_previous %}
              &lt;a href="?page={{ employerList.previous_page_number }}"&gt;previous&lt;/a&gt;
          {% endif %}
  
          &lt;span class="current"&gt; Page {{ employerList.number }} of {{ employerList.paginator.num_pages }}.&lt;/span&gt;
          {% if employerList.has_next %}
              &lt;a href="?page={{ employerList.next_page_number }}"&gt;next&lt;/a&gt;
          {% endif %}
      &lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This example works great however as you can see, for every navigation I need to get all <code>Employer</code> objects. After that <code>Paginator</code> handles the objects in query depending on page number. However, I think the pagination should be done during query and only get X objects that I want depending on page number. I can modify, of course, the code in that manner but I can't  figure out why people use <code>Paginator</code> although there is such overhead. I may overlook a detail...</p>
  
  <p>My second question is how can I apply sort my list ? Should I modify my <code>url</code> and passing a sort method and page number, and depending on them get the quesy by sort method and give it to <code>Paginator</code> ?</p>
  
  <p>This seems reasonable and fine by me but I just wonder is there any better approach to do in django.</p>
  
  <p>Thanks</p>