Dynamically Populate Wtform Selectfield With Sqlalchemy Query
I'm trying to dynamically populate options in a drop down with data from a column in my postgreSQL database. When I try to load my form I get: TypeError: 'NoneType' object is not i
Solution 1:
I should have been using QuerySelectField and lambda and added repr in my models. This is what worked for me:
Forms.py
coi_name = QuerySelectField(label='COI', query_factory=lambda: db.session.query(Coi).filter_by(active=1), get_pk=lambda coi_id: coi_id, get_label=lambda coi_name: coi_name, allow_blank=True)
Models.py
def__repr__(self):
return'{}'.format(self.coi_name)
Post a Comment for "Dynamically Populate Wtform Selectfield With Sqlalchemy Query"