Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

how to change subgroup when group selection field changed in Flask Forms?

I have products table with categories in SQL Alchemy ORM. So, I want a solution for this problem:

when I change Group Field, how to reload subgroup fields in HTML with Ajax in a dynamically way (Flask). This is My WTF From: how can I fill parent_id dynamically, without hardcode and system can find user now want these subgroups. "

parent_id = 1 ==> is Wrong"

...
    group = QuerySelectField(query_factory=lambda: ProductGroup.query.filter_by(parent_id = None).all(),
                            get_label="id")
    subgroup = QuerySelectField(query_factory=lambda: ProductGroup.query.filter_by(parent_id = 1).all(),
                            get_label="id")

This is HTML Loader:

                        <div class="form-group">
                          {{ form.group.label }}
                          {{ form.group(class_= "form-control") }}
                        </div>
                        <div class="form-group">
                          {{ form.subgroup.label }}
                          {{ form.subgroup(class_= "form-control") }}
                        </div>