You must select both forms in the form set.

I have a set of forms that has two forms.

forms:

class PresClinicForm(forms.Form): _names = list(PresClinic.objects.values_list('pres_clinic_id', 'pres_clinic_name')) _names.append(["New", u'Nova entrada']) pres_name = forms.ChoiceField(widget=RadioSelect(), choices=_names, label= "", required=True) PresClinicFormSet = formset_factory(PresClinicForm, extra=2) 

Views:

 if request.method == 'POST': formset1 = PresClinicFormSet(request.POST, request.FILES, prefix='pres_clinic') if formset1.is_valid(): choice = formset1.cleaned_data return render_to_response('template.html', {'options': options}) 

template:

  <form method="post" action=""> <div> {{ formset1.management_form}} {% for form in formset1.forms %} {{ form }} {% endfor %} <input type="submit" value="Guardar" /> </div> </form> 

The user must select one option in each form.
I tried require = True in forms.py, but if I select only one parameter, it works anyway.

It should not work if the user selects only an option. This is what I am trying to implement ..

Does anyone know how to do this?

Thanks in advance for your help!

0
source share
2 answers

Please mark the question to the question: Django: Are all forms of forms required?

Be careful, you can only use formet with django 1.3, and django 1.1 cleaned_data gives an error.

0
source

You can use Matthew Flanagan's code, requiring at least one form in the form set to be valid as a starting point and integrate it into your workflow: http://wadofstuff.blogspot.com/2009/08/requiring-at-least -one-inline-formset.html

Hope this helps you.

0
source

All Articles