diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
index 0dd0692e29..996e353775 100644
--- a/django/newforms/widgets.py
+++ b/django/newforms/widgets.py
@@ -189,6 +189,10 @@ class RadioFieldRenderer(StrAndUnicode):
for i, choice in enumerate(self.choices):
yield RadioInput(self.name, self.value, self.attrs.copy(), choice, i)
+ def __getitem__(self, idx):
+ choice = self.choices[idx] # Let the IndexError propogate
+ return RadioInput(self.name, self.value, self.attrs.copy(), choice, idx)
+
def __unicode__(self):
"Outputs a
for this set of radio fields."
return u'' % u'\n'.join([u'- %s
' % w for w in self])
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index a3445d7176..6bf64422fb 100644
--- a/tests/regressiontests/forms/tests.py
+++ b/tests/regressiontests/forms/tests.py
@@ -514,6 +514,25 @@ beatle J P Paul False
beatle J G George False
beatle J R Ringo False
+A RadioFieldRenderer object also allows index access to individual RadioInput
+objects.
+>>> w = RadioSelect()
+>>> r = w.render('beatle', 'J', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo')))
+>>> print r[1]
+
+>>> print r[0]
+
+>>> r[0].is_checked()
+True
+>>> r[1].is_checked()
+False
+>>> r[1].name, r[1].value, r[1].choice_value, r[1].choice_label
+('beatle', u'J', 'P', 'Paul')
+>>> r[10]
+Traceback (most recent call last):
+...
+IndexError: list index out of range
+
# CheckboxSelectMultiple Widget ###############################################
>>> w = CheckboxSelectMultiple()