summaryrefslogtreecommitdiff
path: root/django/forms/formsets.py
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-06-28 17:32:57 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-06-28 17:32:57 +0100
commit7a47ba6f6aeca36b8b092dbafd36abb342d34d4b (patch)
treee959922f7d4d08057225459e31697f410e26df26 /django/forms/formsets.py
parente2d7e83256234251a81ad3388428f6579795a672 (diff)
parent48dd1e63bbb93479666208535a56f8c7c4aeab3a (diff)
Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts: django/db/backends/__init__.py django/db/models/fields/related.py tests/field_deconstruction/tests.py
Diffstat (limited to 'django/forms/formsets.py')
-rw-r--r--django/forms/formsets.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index edd362c595..cb3126e6d7 100644
--- a/django/forms/formsets.py
+++ b/django/forms/formsets.py
@@ -4,8 +4,9 @@ from django.core.exceptions import ValidationError
from django.forms import Form
from django.forms.fields import IntegerField, BooleanField
from django.forms.util import ErrorList
-from django.forms.widgets import Media, HiddenInput
+from django.forms.widgets import HiddenInput
from django.utils.encoding import python_2_unicode_compatible
+from django.utils.functional import cached_property
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.six.moves import xrange
@@ -55,8 +56,6 @@ class BaseFormSet(object):
self.error_class = error_class
self._errors = None
self._non_form_errors = None
- # construct the forms in the formset
- self._construct_forms()
def __str__(self):
return self.as_table()
@@ -125,12 +124,14 @@ class BaseFormSet(object):
initial_forms = len(self.initial) if self.initial else 0
return initial_forms
- def _construct_forms(self):
- # instantiate all the forms and put them in self.forms
- self.forms = []
+ @cached_property
+ def forms(self):
+ """
+ Instantiate forms at first property access.
+ """
# DoS protection is included in total_form_count()
- for i in xrange(self.total_form_count()):
- self.forms.append(self._construct_form(i))
+ forms = [self._construct_form(i) for i in xrange(self.total_form_count())]
+ return forms
def _construct_form(self, i, **kwargs):
"""