title: Django ListView pagination using get_queryset
body: <p>I have been trying to learn and get to grips with ListViews with pagination in Django, but I seem to be having some trouble in understanding concepts. So, let me show some code - my view.py looks something like this:</p>
  
  <pre><code>class SearchDisplayListView(ListView):
      model = BlogPosts
      template_name = "searchres_list.html"
      paginate_by = '15'
      context_object_name = "searchres"
  
      def get_context_data(self, **kwargs):
          context = super(SearchDisplayListView, self).get_context_data(**kwargs)
          q = self.request.GET.get('q')
          q = q.replace(" ","+")
          context['searchq'] = q
          return context
  
      def get_queryset(self):
          queryset = super(SearchDisplayListView, self).get_queryset()
          # Get the q GET parameter
          q = self.request.GET.get('q')
          q = q.replace(" ","+")
          if q is None:
          # Return the base queryset
          return queryset
          # Return a filtered queryset
         ## do some awesome calculations using "q" i.e send request to search server
         ## get back a list from the search server.. example: range(0,100)
          queryset = range(0,100)
          return queryset
  </code></pre>
  
  <p>As you can see, I do not actually populate my queryset using Models - but rather from my own "search server" which returns me results - say in this example range(0,100).</p>
  
  <p>Now, I am trying to use the following in my template code:</p>
  
  <pre><code>&lt;table class="table table-hover"&gt;
  &lt;tbody&gt;
  {% for i in searchres %}
  &lt;tr&gt;
  &lt;td&gt;&lt;img src="http://placehold.it/140x140" class="img-polaroid"&gt;&lt;/td&gt;
  &lt;td&gt;{{i}}&lt;/td&gt;
  &lt;/tr&gt;
  {% endfor %}
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>and my pagination looks as follows:</p>
  
  <pre><code>{% if is_paginated %}
  &lt;div class="pagination pagination-centered"&gt;
      &lt;ul&gt;
          {% if page_obj.has_previous %}
  &lt;li&gt;&lt;a href="/search/?q={{searchq}}/page={{ page_obj.previous_page_number }}"&gt;Prev&lt;/a&gt;&lt;/li&gt;
          {% endif %}
  
          {% for i in paginator.page_range %}
              {% if page_obj.has_next %}
  &lt;li&gt;&lt;a href="/search/?q={{searchq}}/page={{ page_obj.number }}"&gt;{{i}}&lt;/a&gt;&lt;/li&gt;
              {% endif %}
          {% endfor %}
  
          {% if page_obj.has_next %}
  &lt;li&gt;&lt;a href="/search/?q={{searchq}}/page={{ page_obj.next_page_number }}"&gt;Next&lt;/a&gt;&lt;/li&gt;
          {% endif %}
  
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Now, I have the following problems:</p>
  
  <p>[1] Although the template seems to paginate the first set (i.e 0 to 14), I am not able to see the other values in the subsequent pages. So, when I click on next page, I get:</p>
  
  <pre><code> - http://mydata:8000/search/?q=myquery/page=2
  </code></pre>
  
  <p>and when I click next page again, I get:</p>
  
  <pre><code> - http://mydata:8000/search/?q=boots/page=2/page=2
  </code></pre>
  
  <p>which is obviously wrong. I am not able to see how I can generate:</p>
  
  <pre><code> - http://mydata:8000/search/?q=boots/page=3
  </code></pre>
  
  <p>[2] Even when I manually set:</p>
  
  <pre><code> - http://mydata:8000/search/?q=boots/page=3
  </code></pre>
  
  <p>I see values again from 0 to 14 rather than the logical set in page:3. </p>
  
  <p>Also, this basically tells me that on each page, the get_queryset seems to run, generating the first 0 to 14 values - which is not what I want.</p>
  
  <p>As you can see, I have my own custom data set in get_queryset - rather than any DB interaction - so, I am unsure how I can paginate this custom data.</p>
  
  <p>Thanks for your time reading my rather long post!</p>