as said in the title I'm supposed to query a database(SQLAlchemy) in a sequential manner: most of the data come from a checkbox in the HTML, I know that I can just do all the queries in one line but, here the problem: I've to query only the value that are going to be True, and obviously I can't foresee how many. So I'm asking if any of you knows a method to do so correctly, moreover I didn't find anything about nulling the booleans that are not True. Thanks for helping me!
Here is the code, I'm sure that there are not problem in the Database or in the HTML, but it just about how to do so.
if request.method == 'POST':
post_city = str(request.form['city'])
post_nation = str(request.form['nation'])
post_tools = request.form.get('fitness_tools')
post_pub = request.form.get('pub_presence')
post_games = request.form.get('games')
post_crowded = request.form.get('crowded')
post_fountain = request.form.get('fountain')
list_of_parks1 = Parks.query.filter_by(city=post_city, nation=post_nation).all()
if post_tools:
list_of_parks2 = Parks.query.filter_by(fitness_tools=post_tools).all()
if post_pub:
list_of_parks3 = Parks.query.filter_by(pub_presence=post_pub).all()
if post_games:
list_of_parks4 = Parks.query.filter_by(children_games=post_games).all()
if post_crowded:
list_of_parks5 = Parks.query.filter_by(crowded=post_crowded).all()
if post_fountain:
list_of_parks6 = Parks.query.filter_by(fountain=post_fountain).all()
list_of_parks = Parks.query.filter_by(city=post_city, nation=post_nation).all()
if list_of_parks:
session['parks_list'] = list_of_parks.id_park