I've been experiencing a weird problem, regarding Django 1.4 and formsets: when the submitted data is unchanged, the cleaned_data field of the formset is empty, even if the formset itself passes the validation.
Here is an example:
forms.py:
class NameForm(forms.Form):
name = forms.CharField(required=False, initial='Foo')
views.py:
def welcome(request):
Formset = formset_factory(NameForm, extra=1)
if request.method == 'POST':
formset = Formset(request.POST)
print '1.Formset is valid?', formset.is_valid()
print '2.Formset', formset
print '3.Formset cleaned_data', formset.cleaned_data
else:
formset = Formset()
return render_to_response('template.html', locals())
Although formset
is valid, and it actually contains data, line 3 prints a list of an empty dictionary, unless I've actually changed the initial value in the field.
This seems weird to me, but I'm probably doing something wrong. Any help?