from app.models import Glacier, Annual_Data, User from app import db def query_annual_data(form): annual_data = db.session.query(Annual_Data).filter_by(year=form.year.data) query = annual_data if form.name.data: query = ( db.session.query(Annual_Data) .filter_by(year=form.year.data) .join(Glacier, Glacier.id == Annual_Data.id) .filter_by(name=form.name.data) .group_by(Glacier.id) ) return query def query_user(form): user = User.query.filter_by(username=form.username.data).first() return user