Skip to content

Commit

Permalink
Refs #15667 -- Fixed crash when indexing RadioFieldRenderer with Mode…
Browse files Browse the repository at this point in the history
…lChoiceIterator.

Regression in 8657386
  • Loading branch information
timgraham committed Jun 18, 2016
1 parent f7a363e commit 26d0023
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion django/forms/widgets.py
Expand Up @@ -693,7 +693,7 @@ def __init__(self, name, value, attrs, choices):
self.choices = choices

def __getitem__(self, idx):
choice = self.choices[idx] # Let the IndexError propagate
choice = list(self.choices)[idx] # Let the IndexError propagate
return self.choice_input_class(self.name, self.value, self.attrs.copy(), choice, idx)

def __str__(self):
Expand Down
7 changes: 7 additions & 0 deletions tests/model_forms/tests.py
Expand Up @@ -1593,6 +1593,13 @@ class ModelChoiceForm(forms.Form):
with self.assertNumQueries(1):
template.render(Context({'field': field}))

def test_modelchoicefield_index_renderer(self):
field = forms.ModelChoiceField(Category.objects.all(), widget=forms.RadioSelect)
self.assertEqual(
str(field.widget.get_renderer('foo', [])[0]),
'<label><input name="foo" type="radio" value="" /> ---------</label>'
)

def test_modelchoicefield_iterator(self):
"""
Iterator defaults to ModelChoiceIterator and can be overridden with
Expand Down

0 comments on commit 26d0023

Please sign in to comment.