This is from the QuerySelectField documentation:
The query property on the field can be set from within a view to assign a query per-instance to the field. If the property is not set, the query_factory callable passed to the field constructor will be called to obtain a query.
What this means is that you define your form with the query:
class transactionsForm(Form): loan_id = QuerySelectField('trans_id', validators=[Required()], get_label='name')
And then in your view function you assign the query once you have an instance:
def viewFunction(my_variable): form = transactionsForm() my_query = trans.query.filter_by(trans_id=my_variable) form.loan_id.query = my_query if form.validate_on_submit(): # ...