title: django model search form
body: <p>Firstly, I did my homework and looked around before posting! My question seems like a very basic thing that must’ve been covered before.</p>
  
  <p>I'm now looking at <a href="https://github.com/alex/django-filter" rel="nofollow">Django-filter</a>  as a potential solution, but would like some advice on if this is the right way to go and if there any other solutions.</p>
  
  <p>I have a Django app wit 10 models, each model has a few fields. Most fields are <code>ChoiceField</code> that users populate using forms with the default <code>select</code> widget. There is a separate form for each model.</p>
  
  <p>I want to create a separate form for each model (in separate views) that users will use to search the database. The search form will contain only drop-down boxes (the <code>select</code> widgets) with the same choices as the forms used to populate the database with the addition of the “any” option.</p>
  
  <p>I know how to use <code>.object.filter()</code>, however the “any” option would correspond to not include specific fields in the filter and I'm not sure how to add model fields to the filter based on users’ selection</p>
  
  <p>I briefly looked at Haystack as an option but it seems to be made for full text search rather than “model filed search” I'm after.</p>
  
  <p>Sample model (simplified):</p>
  
  <pre><code>class Property():             
        TYPE_CHOICES = (‘apartment’, ‘house’, ‘flat’)        
        type = charfield(choices=TYPE_CHOICES)
        LOC_CHOICES = (‘Brussels’, ‘London’, ‘Dublin’, ‘Paris’)
        location = charfield(choices=LOC_CHOICES)
        price = PostivieInteger()
  </code></pre>
  
  <p>Users can select only “type”, only “location” or both (not making selection is equal to ANY) in which case I end up with 3 different filters:</p>
  
  <pre><code>Property.objects.filter(type=’apartment’)
  Property.objects.filter(location=’Dublin’)
  Property.objects.filter(type=’apartment’, location=’Dublin’)
  </code></pre>
  
  <p>The main question: django-filter the best option?</p>
  
  <pre><code>Question 1: what’s the best option of accomplishing this overall? 
  Question 2: how do I add model fields to the filter based on user’s form selection?
  Question 3: how do I do the filter based on user selection? (I know how to use .filter(price_lt=).exclude(price_gt=) but again how do I do it dynamically based on selection as “ANY” would mean this is not included in the query)
  </code></pre>