8000 .choices property of RelatedField should preserve non-string values. … · encode/django-rest-framework@f1a2eeb · GitHub
[go: up one dir, main page]

Skip to content

Commit f1a2eeb

Browse files
authored
.choices property of RelatedField should preserve non-string values. (#4379)
Update RelatedField.choices to support non-string values
1 parent 9857cd9 commit f1a2eeb

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

rest_framework/relations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def get_choices(self, cutoff=None):
168168

169169
return OrderedDict([
170170
(
171-
six.text_type(self.to_representation(item)),
171+
self.to_representation(item),
172172
self.display_value(item)
173173
)
174174
for item in queryset

tests/test_model_serializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ class Meta:
614614
fields = '__all__'
615615

616616
serializer = TestSerializer()
617-
expected = OrderedDict([('1', 'Red Color'), ('2', 'Yellow Color'), ('3', 'Green Color')])
617+
expected = OrderedDict([(1, 'Red Color'), (2, 'Yellow Color'), (3, 'Green Color')])
618618
self.assertEqual(serializer.fields['color'].choices, expected)
619619

620620
def test_custom_display_value(self):
@@ -630,7 +630,7 @@ class Meta:
630630
fields = '__all__'
631631

632632
serializer = TestSerializer()
633-
expected = OrderedDict([('1', 'My Red Color'), ('2', 'My Yellow Color'), ('3', 'My Green Color')])
633+
expected = OrderedDict([(1, 'My Red Color'), (2, 'My Yellow Color'), (3, 'My Green Color')])
634634
self.assertEqual(serializer.fields['color'].choices, expected)
635635

636636

0 commit comments

Comments
 (0)
0