File tree 2 files changed +17
-2
lines changed
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):
137
137
elif getattr (field , 'fields' , None ):
138
138
field_info ['children' ] = self .get_serializer_info (field )
139
139
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' )):
141
143
field_info ['choices' ] = [
142
144
{
143
145
'value' : choice_value ,
Original file line number Diff line number Diff line change 11
11
from rest_framework .request import Request
12
12
from rest_framework .test import APIRequestFactory
13
13
14
+ from .models import BasicModel
15
+
14
16
request = Request (APIRequestFactory ().options ('/' ))
15
17
16
18
@@ -261,10 +263,21 @@ def get_serializer(self):
261
263
view = ExampleView .as_view (versioning_class = scheme )
262
264
view (request = request )
263
265
266
+
267
+ class TestSimpleMetadataFieldInfo (TestCase ):
264
268
def test_null_boolean_field_info_type (self ):
265
269
options = metadata .SimpleMetadata ()
266
270
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 )
268
281
269
282
270
283
class TestModelSerializerMetadata (TestCase ):
You can’t perform that action at this time.
0 commit comments