Ticket #15722: 15722.diff

File 15722.diff, 1.3 KB (added by Mark Lavin, 13 years ago)

Patch for fix with test.

  • django/forms/formsets.py

    diff --git a/django/forms/formsets.py b/django/forms/formsets.py
    a b  
    6060    def __len__(self):
    6161        return len(self.forms)
    6262
     63    def __nonzero__(self):
     64        """All formsets have a management form which is not included in the length"""
     65        return True
     66
    6367    def _management_form(self):
    6468        """Returns the ManagementForm instance for this FormSet."""
    6569        if self.is_bound:
  • tests/regressiontests/forms/tests/formsets.py

    diff --git a/tests/regressiontests/forms/tests/formsets.py b/tests/regressiontests/forms/tests/formsets.py
    a b  
    805805        self.assertEqual(str(reverse_formset[1]), str(forms[-2]))
    806806        self.assertEqual(len(reverse_formset), len(forms))
    807807
     808    def test_formset_nonzero(self):
     809        """
     810        Formsets with no forms should still evaluate as true.
     811        Regression test for #15722
     812        """
     813        ChoiceFormset = formset_factory(Choice, extra=0)
     814        formset = ChoiceFormset()
     815        self.assertEqual(len(formset.forms), 0)
     816        self.assertTrue(formset)
     817
     818
    808819data = {
    809820    'choices-TOTAL_FORMS': '1', # the number of forms rendered
    810821    'choices-INITIAL_FORMS': '0', # the number of forms with initial data
Back to Top