title: Django pagination in filtered search post results
body: <p>I have a view that filters out results for a posted search form: </p>
  
  <pre><code>def profile_advanced_search(request):
      args = {}
      if request.method == "POST":
          form = AdvancedSearchForm(request.POST)
          qs=[]
          if form.is_valid():
              cd = form.cleaned_data
  
              s_country=cd['country']
              s_province=cd['province']
              s_city = cd['city']
  
              if s_country: qs.append(Q(country__icontains = s_country))    
              if s_province: qs.append( Q(province__icontains=s_province))                
              if s_city: qs.append( Q(city__icontains=s_city))
  
  
  
              f = None
              for q in qs:
                  if f is None: 
                      f=q 
  
                  else: f &amp;=q
              list = UserProfile.objects.filter(f).order_by('-created_at') 
  
  
      else:
          form = AdvancedSearchForm()
          list = UserProfile.objects.all().order_by('-created_at')
  
      paginator = Paginator(list,10)            
      page= request.GET.get('page')
      try:
          results = paginator.page(page)
      except PageNotAnInteger:
          results = paginator.page(1)  
  
      except EmptyPage:
              results = paginator.page(paginator.num_pages)        
  
      args.update(csrf(request))    
      args['form'] = form  
      args['results'] = results
      return render_to_response('userprofile/advanced_search.html', args,
                                context_instance=RequestContext(request))  
  </code></pre>
  
  <p>the urls.py part is:</p>
  
  <pre><code>url(r'^search/$', 'userprofile.views.profile_advanced_search'),
  </code></pre>
  
  <p>The results in the first page are fine but the problem is that when I go to the second page, the filtered results is just forgotten. </p>
  
  <p>It is obvious to me why this happnes: filtering in the views accounts only for POST while pagination uses GET hence the queryset filter does not apply after the first page. </p>
  
  <p>I have looked at several suggestions and <a href="https://djangosnippets.org/snippets/1592/" rel="nofollow">snippets</a> for similar problem but none was close enough to my views, so I could not figure out how to fix it and appreciate your help.</p>
  
  <p>Update: here is the relevant template:</p>
  
  <pre><code>&lt;form action="/search/" method="post"&gt;{% csrf_token %}
  
            &lt;ul class="list-unstyled"&gt;
  
              &lt;li&gt;&lt;h3&gt;Country&lt;/h3&gt;&lt;/li&gt;
              &lt;li&gt;{{form.country}}&lt;/li&gt;&lt;br&gt; 
              &lt;h4&gt;Province&lt;/h4&gt;
              &lt;li&gt;{{form.province}}&lt;/li&gt;
                &lt;h4&gt;City&lt;/h4&gt;
              &lt;li&gt;{{form.city}}&lt;/li&gt;
  
  
            &lt;/ul&gt;
  
  &lt;input  type="submit" name="submit"  value="search" /&gt;
  
   &lt;/form&gt;
       Search Results:
  {% for p in results %}
  
              &lt;div"&gt;
                    &lt;div&gt;
                        &lt;br&gt;
                         &lt;strong&gt;&lt;a href="/profile/{{p.username}}" &gt;{{p.username}}&lt;/a&gt;&lt;/strong&gt;
                           {{p.country}} &lt;br&gt;
                           {{p.province}} &lt;br&gt;
                           {{p.city}} &lt;br&gt;
  
                       &lt;/div&gt;
                    &lt;/div&gt;
  {% endfor %}
  
  
  
  &lt;div&gt;
      &lt;div class="pagination"&gt;
        {% if results.has_previous %}
            &lt;a href="?page={{ results.previous_page_number }}"&gt; &lt;&lt; Prev &lt;/a&gt;&amp;nbsp;&amp;nbsp
        {% endif %}
  
         {% if results.has_next %}
            &lt;a href="?page={{ results.next_page_number }}"&gt; Next &gt;&gt; &lt;/a&gt;
        {% endif %}
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>