diff --git a/django/forms/formsets.py b/django/forms/formsets.py index 6d92236..6a814d4 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -48,6 +48,14 @@ class BaseFormSet(StrAndUnicode): def __unicode__(self): return self.as_table() + + def __iter__(self): + """Yields the forms in the order they should be rendered""" + return iter(self.forms) + def __getitem__(self, index): + return list(self)[index] + def __len__(self): + return len(list(self)) def _management_form(self): """Returns the ManagementForm instance for this FormSet.""" @@ -323,17 +331,17 @@ class BaseFormSet(StrAndUnicode): # XXX: there is no semantic division between forms here, there # probably should be. It might make sense to render each form as a # table row with each field as a td. - forms = u' '.join([form.as_table() for form in self.forms]) + forms = u' '.join([form.as_table() for form in self]) return mark_safe(u'\n'.join([unicode(self.management_form), forms])) def as_p(self): "Returns this formset rendered as HTML
s." - forms = u' '.join([form.as_p() for form in self.forms]) + forms = u' '.join([form.as_p() for form in self]) return mark_safe(u'\n'.join([unicode(self.management_form), forms])) def as_ul(self): "Returns this formset rendered as HTML