Refs #15667 -- Fixed crash when indexing RadioFieldRenderer with ModelChoiceIterator.
Regression in 86573861a9
This commit is contained in:
parent
f7a363ee1d
commit
26d0023ccc
|
@ -693,7 +693,7 @@ class ChoiceFieldRenderer(object):
|
||||||
self.choices = choices
|
self.choices = choices
|
||||||
|
|
||||||
def __getitem__(self, idx):
|
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)
|
return self.choice_input_class(self.name, self.value, self.attrs.copy(), choice, idx)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -1593,6 +1593,13 @@ class ModelChoiceFieldTests(TestCase):
|
||||||
with self.assertNumQueries(1):
|
with self.assertNumQueries(1):
|
||||||
template.render(Context({'field': field}))
|
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):
|
def test_modelchoicefield_iterator(self):
|
||||||
"""
|
"""
|
||||||
Iterator defaults to ModelChoiceIterator and can be overridden with
|
Iterator defaults to ModelChoiceIterator and can be overridden with
|
||||||
|
|
Loading…
Reference in New Issue