When you bind the posted data to the form, the field validation is performed based upon the queryset defined for that field.
This means that in a POST, you either want to:
- Set the queryset for all fields, then use a custom
cleanfunction to ensure the submission is valid for that combination of fields. - Add more logic to your form’s
__init__method to alter the queryset as necessary. - Create the instance of the form, and modify the field in the view after the instance of the form has been created but before it is validated.
You might want to see the thread at cascading selection and fetch data from database (htmx and django) and the threads that it references.