Tuesday, 15 April 2014

inserting variables and looping over a python class call -



inserting variables and looping over a python class call -

i'm using flask-sqlalchemy , flask-wtf. want take string produced "row.form_field" query , place wtf form class call. ideas on how can pull off?

from forms import form_list models import form_value form = form_list values = form_value.query.filter_by(form_entry_id = id) row in values: print row.form_field, row.value #this works. form.row.form_field.data = row.value #this not! # form.???how insert "row.form_field" here???.data = row.value

you can utilize getattr:

getattr(form, row.form_field).data = row.value

but easier, can pass info instantiated wtforms class:

data = {row.form_field: row.value row in values} form_list = formlist(**data)

python class flask flask-sqlalchemy flask-wtforms

No comments:

Post a Comment