mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge 75c80087b8
into 99382f3ccb
This commit is contained in:
commit
d4eaceb71c
|
@ -9,6 +9,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import decimal
|
||||
from collections import OrderedDict
|
||||
import pytest
|
||||
|
||||
import pytest
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
|
@ -685,6 +686,22 @@ class TestRelationalFieldDisplayValue(TestCase):
|
|||
expected = OrderedDict([(1, 'My Red Color'), (2, 'My Yellow Color'), (3, 'My Green Color')])
|
||||
self.assertEqual(serializer.fields['color'].choices, expected)
|
||||
|
||||
def test_to_representation_returns_dict_type(self):
|
||||
class TestField(serializers.RelatedField):
|
||||
def to_representation(self, value):
|
||||
return {'id': value.id}
|
||||
|
||||
class TestSerializer(serializers.ModelSerializer):
|
||||
color = TestField(queryset=DisplayValueTargetModel.objects.all())
|
||||
|
||||
class Meta:
|
||||
model = DisplayValueModel
|
||||
fields = '__all__'
|
||||
|
||||
serializer = TestSerializer()
|
||||
expected = OrderedDict([("{'id': 1}", 'Red Color'), ("{'id': 2}", 'Yellow Color'), ("{'id': 3}", 'Green Color')])
|
||||
self.assertEqual(serializer.fields['color'].choices, expected)
|
||||
|
||||
|
||||
class TestIntegration(TestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user