title: Django Search bar with ListView
body: <p>I am trying to add a search bar to a ListView. When I click search the result show fine but when I click on second page of result I get the whole result.</p>
  
  <pre class="lang-py prettyprint-override"><code>class LegsIndex(FormMixin, generic.ListView):
      form_class = MyForm
      model = Legs
      paginate_by = 5
      template_name = "legs/legshome.html"
  
      def get_queryset(self):
          return self.model.objects.published()
  
      def get_context_data(self, **kwargs):
          context = super(LegsIndex, self).get_context_data(**kwargs)
          return context
  
      def get(self, request, *args, **kwargs):
          form_class = self.get_form_class()
          self.form = self.get_form(form_class)
  
          search = request.GET.get('search', None)
  
          if search:
              self.object_list = self.get_queryset().filter(title__icontains=search)
          else:
              self.object_list = self.get_queryset()
  
          context = self.get_context_data(object_list=self.object_list, form=self.form)
          return self.render_to_response(context)
  </code></pre>
  
  <p>What is the proper way of doing this. I need filter these fields in form only if any of them is set, otherwise show all data.</p>
  
  <pre class="lang-py prettyprint-override"><code>class MyFilterForm(Form):
  
      search = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Looking For ...'}), required=False)
      counties = forms.ModelMultipleChoiceField(queryset=Legs.objects.values_list('country', flat=True).distinct(),
                                                widget=forms.CheckboxSelectMultiple(), required=False)
      cities = forms.ModelMultipleChoiceField(queryset=Legs.objects.values_list('city', flat=True).distinct(),
                                              widget=forms.CheckboxSelectMultiple(), required=False)
  
      class Meta:
          fields = '__all__'
  </code></pre>