File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,9 @@ def get_field_info(self, field):
137137 elif getattr (field , 'fields' , None ):
138138 field_info ['children' ] = self .get_serializer_info (field )
139139
140- if not field_info .get ('read_only' ) and hasattr (field , 'choices' ):
140+ if (not field_info .get ('read_only' ) and
141+ not isinstance (field , serializers .RelatedField ) and
142+ hasattr (field , 'choices' )):
141143 field_info ['choices' ] = [
142144 {
143145 'value' : choice_value ,
Original file line number Diff line number Diff line change 1111from rest_framework .request import Request
1212from rest_framework .test import APIRequestFactory
1313
14+ from .models import BasicModel
15+
1416request = Request (APIRequestFactory ().options ('/' ))
1517
1618
@@ -261,10 +263,21 @@ def get_serializer(self):
261263 view = ExampleView .as_view (versioning_class = scheme )
262264 view (request = request )
263265
266+
267+ class TestSimpleMetadataFieldInfo (TestCase ):
264268 def test_null_boolean_field_info_type (self ):
265269 options = metadata .SimpleMetadata ()
266270 field_info = options .get_field_info (serializers .NullBooleanField ())
267- assert field_info ['type' ] == 'boolean'
271+ self .assertEqual (field_info ['type' ], 'boolean' )
272+
273+ def test_related_field_choices (self ):
274+ options = metadata .SimpleMetadata ()
275+ BasicModel .objects .create ()
276+ with self .assertNumQueries (0 ):
277+ field_info = options .get_field_info (
278+ serializers .RelatedField (queryset = BasicModel .objects .all ())
279+ )
280+ self .assertNotIn ('choices' , field_info )
268281
269282
270283class TestModelSerializerMetadata (TestCase ):
You can’t perform that action at this time.
0 commit comments