Answer the question
In order to leave comments, you need to log in
Flask WTForms SelectField, how to generate a choice parameter while changing data on a form?
Good afternoon!
I'm new to Python and Flask (so sorry for the terms)
In short, I'll formulate the question:
I have a form with 4 fields and one button
like this
*———————————-
class RpaForm(FlaskForm):
title = StringField('Title', validators
area = SelectField('Automation Area', coerce=int)
cat = SelectField('Automation Category', coerce=int)
subcat = SelectField('Automation SubCategory', coerce=int)
submit = SubmitField( 'Save')
*————————————————
3 SelectFields from 3 different related tables
Roughly speaking, when selecting the AREA element, I need to filter the CAT table and show it in SelectField cat, well, from what I chose in cat, I need to filter the SUBCAT table and put the result in SelectField Subcat.
before sending data to the form (I don’t know what to call it) and render_template, of
course I do it all like this
*——————————————————-
form.area.choices = [(g .id, g.title) for g in Rpaarea.query.all ()]
form.cat.choices = [(c.id, c.title) for c in Rpacat.query.filter ( Rpacat.id_rpa == post. rpaarea ).all ()]
form.subcat.choices = [(b.id, b.title) for b in Rpasubcat.query.filter ( Rpasubcat.id_rpacat == post.rpacat ).all ()]
*——— ———————————————–
QUESTION: how can I change the filter conditions for CAT and so on when choosing an OTHER value in the AREA list.
Poke your nose ))))) I'm sure there is a simple and elegant solution.
Thank you in advance
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question