title: Python Flask SQLalchemy query filter by boolean values ignore False
body: <p>In my database I have rooms, these rooms have multiple boolean values like <code>has_tv</code>.</p>
  
  <p>A user can search for a room in a city, he will be redirected to the result page, where he finds all rooms in the searched city.</p>
  
  <p>Now there is a filter function which filters the current result set, by rooms which for example have a tv. For this the user checks a checkbox with the value <code>has_tv</code></p>
  
  <p>I managed to make it work, but it does not ignore False values. this means if a user check <code>has_tv</code> it will be true but all the other boolean values will be false (because they are unchecked). So this will show me only results where has_tv is true and all others false, I need to see results where has_tv is true and others are irrelevant, some can be false and true.</p>
  
  <p>Thats what I use atm:</p>
  
  <pre><code>if form.validate_on_submit():
      all_rooms_in_city = Zimmer.query.filter(or_(Zimmer.haustiere_erlaubt.is_(form.haustiere_erlaubt.data), Zimmer.bettwaesche_wird_gestellt.is_(form.bettwaesche_wird_gestellt.data))).all()
  else:
      all_rooms_in_city = Zimmer.query.order_by(desc("stadt")).all()
  </code></pre>
  
  <p>That are all values which can be checked (there are a lot, so hardcoding all possibilites is impossible):</p>
  
  <pre><code>class FilterZimmerForm(Form):
      haustiere_erlaubt = BooleanField("Haustiere")
      bettwaesche_wird_gestellt = BooleanField("Bettwaesche")
      grill_vorhanden = BooleanField("grill_vorhanden")
      safe_vorhanden = BooleanField("safe_vorhanden")
      kuehlschrank_vorhanden = BooleanField("kuehlschrank_vorhanden")
      rauchen_erlaubt = BooleanField("rauchen_erlaubt")
      parkplatz_vorhanden = BooleanField("parkplatz_vorhanden")
      kochmoeglichkeit_vorhanden = BooleanField("kochmoeglichkeit_vorhanden")
      restaurant_im_haus_vorhanden = BooleanField("restaurant_im_haus_vorhanden")
      handtuecher_werden_gestellt = BooleanField("handtuecher_werden_gestellt")
      tv_vorhanden = BooleanField("tv_vorhanden")
      waschmoeglichkeit_vorhanden = BooleanField("waschmoeglichkeit_vorhanden")
      wlan_vorhanden = BooleanField("wlan_vorhanden")
  </code></pre>
  
  <p>Of course later if lets say two of them are checked, it shall show all rooms where the two checked values are true and all others shall not matter!</p>
  
  <p>Here is a screenshot of the website where the function is needed:
  <a href="https://i.stack.imgur.com/7Wq77.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7Wq77.jpg" alt="enter image description here"></a></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It seems I found a solution, have tested a few times and it seems to work as intended but it does not feel like it is best practise:</p>
  
  <pre><code>if form.validate_on_submit():
  
      filter_result = []
  
      if form.haustiere_erlaubt.data == True:
          filter_result.append(Zimmer.haustiere_erlaubt.is_(True))
      if form.bettwaesche_wird_gestellt.data == True:
          filter_result.append(Zimmer.bettwaesche_wird_gestellt.is_(True))
      if form.grill_vorhanden.data == True:
          filter_result.append(Zimmer.grill_vorhanden.is_(True))
      if form.safe_vorhanden.data == True:
          filter_result.append(Zimmer.safe_vorhanden.is_(True))
      if form.kuehlschrank_vorhanden.data == True:
          filter_result.append(Zimmer.kuehlschrank_vorhanden.is_(True))
      if form.rauchen_erlaubt.data == True:
          filter_result.append(Zimmer.rauchen_erlaubt.is_(True))
      if form.parkplatz_vorhanden.data == True:
          filter_result.append(Zimmer.parkplatz_vorhanden.is_(True))
      if form.kochmoeglichkeit_vorhanden.data == True:
          filter_result.append(Zimmer.kochmoeglichkeit_vorhanden.is_(True))           
      if form.restaurant_im_haus_vorhanden.data == True:
          filter_result.append(Zimmer.restaurant_im_haus_vorhanden.is_(True))
      if form.handtuecher_werden_gestellt.data == True:
          filter_result.append(Zimmer.handtuecher_werden_gestellt.is_(True))
      if form.tv_vorhanden.data == True:
          filter_result.append(Zimmer.tv_vorhanden.is_(True))
      if form.waschmoeglichkeit_vorhanden.data == True:
          filter_result.append(Zimmer.waschmoeglichkeit_vorhanden.is_(True))
      if form.wlan_vorhanden.data == True:
          filter_result.append(Zimmer.wlan_vorhanden.is_(True))
  
      for item in filter_result:
          all_rooms_in_city = Zimmer.query.filter(item).all()
  else:
      all_rooms_in_city = Zimmer.query.order_by(desc("stadt")).all()  
  </code></pre>