summaryrefslogtreecommitdiff
path: root/django/forms/forms.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2011-12-07 22:31:39 +0000
committerAdrian Holovaty <adrian@holovaty.com>2011-12-07 22:31:39 +0000
commitfc90c09efdfbc029d43e6d4c0952ed6b49f6f34d (patch)
treeb86bdd032d4afc93cb3135312377cf02532dc68d /django/forms/forms.py
parent0519adb2a87090bd9ee3f61c7b9a6ff6de5fa341 (diff)
Made BoundFields iterable, so that you can iterate over individual radio buttons of a RadioSelect in a template
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17173 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/forms/forms.py')
-rw-r--r--django/forms/forms.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 1400be3014..7818aac13a 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -410,6 +410,16 @@ class BoundField(StrAndUnicode):
return self.as_widget() + self.as_hidden(only_initial=True)
return self.as_widget()
+ def __iter__(self):
+ """
+ Yields rendered strings that comprise all widgets in this BoundField.
+
+ This really is only useful for RadioSelect widgets, so that you can
+ iterate over individual radio buttons in a template.
+ """
+ for subwidget in self.field.widget.subwidgets(self.html_name, self.value()):
+ yield self.as_widget(subwidget)
+
def _errors(self):
"""
Returns an ErrorList for this field. Returns an empty ErrorList