mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
.choices property of RelatedField should preserve non-string values. (#4379)
Update RelatedField.choices to support non-string values
This commit is contained in:
parent
9857cd9889
commit
f1a2eeb818
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user