filtering forms.ModelChoiceField queryset when form.is_valid

Hello Ken, thank you for your time.

On the html form I have two selects. I update de option list from the second select with the choice of the first and a ajax call.

When I submit the form, if the form is valid, the page will be reloaded with the data.

when I choose a value from the first select, the ajax call is made and le the select is updated with the pertinent choices, this works fine.

My issue is that when I submit the form, the page will be reloaded (with the cleaned data) but the options available in the second select are ‘reset’ to the full list.

I probably can manage this with javascript but I was wondering if there was a way to ‘manipulate’ the CertificateSearchForm object within the view after it was submitted and before rendering back?

Specifically here I would have get the code from the cleaned data then return a filtered sub_code with only the pertinent choices (Subcode.objects.fileter(code=code)). And also mark selected the option from the second select if it was set.

I hope it’s clear.