Change field names in Python WTForms -
so got form exists of repeating row of fields, it's defined this:
class simpledatarow(form): title = stringfield('title') label = stringfield('name') class simpledataform(form): fields = fieldlist(formfield(simpledatarow))
after initialize form, , append entries corresponding data:
fields = dbsession.query(field).filter_by(app=request.currentapp).all() form = simpledataform() field in fields: form.fields.append_entry(field)
then want render fields browser, trouble because of field naming in wtforms. when rendering fields assigned name , id of fields-0-title
& fields-0-label
, , each row of data 0 incremented 1.
what rather have wtform takes id of field object, , uses when assigns names , id's fields. field object looks this:
class field(base): __tablename__ = 'sys_fields' id = column(integer, primary_key=true) label = column(string(64)) title = column(string(64))
so there way change pattern wtforms uses name fields in fieldlist's? ideally want naming pattern this: {prefix_}{label}_{id}
you can give prefix when instantiating form class. in case like:
form = simpledataform(prefix=<your prefix string>)
Comments
Post a Comment