.choices property of RelatedField should preserve non-string values. (#4379)

Update RelatedField.choices to support non-string values
This commit is contained in:
Tom Christie 2016-08-10 16:38:59 +01:00 committed by GitHub
parent 9857cd9889
commit f1a2eeb818
2 changed files with 3 additions and 3 deletions

View File

@ -168,7 +168,7 @@ class RelatedField(Field):
return OrderedDict([
(
six.text_type(self.to_representation(item)),
self.to_representation(item),
self.display_value(item)
)
for item in queryset

View File

@ -614,7 +614,7 @@ class TestRelationalFieldDisplayValue(TestCase):
fields = '__all__'
serializer = TestSerializer()
expected = OrderedDict([('1', 'Red Color'), ('2', 'Yellow Color'), ('3', 'Green Color')])
expected = OrderedDict([(1, 'Red Color'), (2, 'Yellow Color'), (3, 'Green Color')])
self.assertEqual(serializer.fields['color'].choices, expected)
def test_custom_display_value(self):
@ -630,7 +630,7 @@ class TestRelationalFieldDisplayValue(TestCase):
fields = '__all__'
serializer = TestSerializer()
expected = OrderedDict([('1', 'My Red Color'), ('2', 'My Yellow Color'), ('3', 'My Green Color')])
expected = OrderedDict([(1, 'My Red Color'), (2, 'My Yellow Color'), (3, 'My Green Color')])
self.assertEqual(serializer.fields['color'].choices, expected)