title: How to exclude empty values in an AND queryset whitout writing if else statements
body: <p>For a real-estate listing site I have a search form with multiple inputs. The user can use one or many fields to filter his search results. The more fields are filled in the more detailed the search should get.</p>
  
  <p>For example: If you only input the zip code all listings that match the zip code should be shown, if you input the zip code and the room number only listings that match both should be shown.
  My forms.py looks like this:</p>
  
  <pre><code>from django import forms
  
  from .models import Property
  
  class PropertyForm(forms.Form):
      zip_code = forms.CharField(required=False)
      rooms = forms.CharField(required=False)
  </code></pre>
  
  <p>Because I need a AND search I had to write a series of conditions in my ListView to query the results:</p>
  
  <p>My views.py looks like this:</p>
  
  <pre><code>class ListPageView(ListView):
      template_name = 'property_list.html'
      model = Property
  
      def get_queryset(self):
          plz = self.request.GET.get('plz')
          rooms = self.request.GET.get('rooms')
          if plz and not rooms:
              object_list = Property.objects.filter(zip_code__exact=plz)
          elif rooms and not plz:
              object_list = Property.objects.filter(rooms__exact=rooms)
          elif plz and rooms:
              object_list = Property.objects.filter(
                  Q(zip_code__icontains=plz) &amp; Q(rooms__exact=rooms)
              )
          else:
              object_list = self.model.objects.none()
  
          return object_list
  </code></pre>
  
  <p>For only two input fields this would suffice but if I add more input fields I quickly have to write a lot of queries. Is there a better way to make AND queries that automatically exclude empty values?</p>