[Answered ]-(Hidden field id) Select a valid choice. That choice is not one of the available choices. (Django)

1👍

I’m new to django but I had to face with the same problem. My solution was to handle singularly each formset inside ‘views.py’.

In the template.html, create a tag for each formset you have, than inside that tag put <input type="submit" name="form1">(Note that name is important and must be different with the respect of the form you are submitting).

Then in views.py, instead for writing if all([sectionformset.is_valid() and materialformset.is_valid()]), try like this:

if 'form1' in request.POST:
     if sectionformset.is_valid():
         sectionformset.save()
         # other rows of your code
     return('success')

if 'form2' in request.POST:
     if materialformset.is_valid():
         materialformset.save()
         # etc. etc.

Leave a comment