Python things
Aus Froggis Wissenssammlung
Version vom 25. Juni 2019, 15:15 Uhr von Froggi (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „When data comes back from the client it is treated as a string by WTForms unless a callable is passed to the coerce keyword argument of the wtforms.fields.Sele…“)
When data comes back from the client it is treated as a string by WTForms unless a callable is passed to the coerce keyword argument of the wtforms.fields.SelectField constructor:
area = SelectField(coerce=int)
Alternately, if you are using SQLAlchemy you could use wtforms.ext.sqlalchemy.fields.QuerySelectField (wtforms_sqlalchemy if you are using WTForms 3+):
area = QuerySelectField(query_factory=Area.objects.all,
get_pk=lambda a: a.id,
get_label=lambda a: a.name)