tags:

views:

56

answers:

1

A formset created based on the inlineformset_factory always returns True if all forms in the formset are valid. It returns also True when the forms in the formset are not filled out. Not filled out means here, that the user did not inserted at least one value. At least this is what I discovered.

Is there a way to get to know that a form in the formset was empty? For example, below I do not want to set the user message, that the object was created, when in fact the object was not created.

CashExpenditureFormSet = inlineformset_factory(Project, CashExpenditure, form=CashExpenditureForm, can_delete=False, extra=1, max_num=1)

    if request.method == 'POST':
        cash_expenditure_formset = CashExpenditureFormSet(request.POST, request.FILES, instance=project)
        if cash_expenditure_formset.is_valid():
            cash_expenditure_formset.save()
            request.user.message_set.create(message='The Cash Expenditure was added successfully to project: "%s".' % project.__str__())
+3  A: 

This is very closely related to an answer I posted on another question, having dealt with this problem myself: http://stackoverflow.com/questions/877723/inline-form-validation-in-django/1884760#1884760

Dan Breen
Thanks. Perfect answer for it.
Tom Tom