@@ -39,6 +39,11 @@ class ExampleSerializer(serializers.Serializer):
39
39
hidden = serializers .HiddenField (default = 'hello' )
40
40
41
41
42
+ class AnotherSerializerWithListFields (serializers .Serializer ):
43
+ a = serializers .ListField (child = serializers .IntegerField ())
44
+ b = serializers .ListSerializer (child = serializers .CharField ())
45
+
46
+
42
47
class AnotherSerializer (serializers .Serializer ):
43
48
c = serializers .CharField (required = True )
44
49
d = serializers .CharField (required = False )
@@ -57,6 +62,13 @@ def custom_action(self, request, pk):
57
62
"""
58
63
return super (ExampleSerializer , self ).retrieve (self , request )
59
64
65
+ @detail_route (methods = ['post' ], serializer_class = AnotherSerializerWithListFields )
66
+ def custom_action_with_list_fields (self , request , pk ):
67
+ """
68
+ A custom action using both list field and list serializer in the serializer.
69
+ """
70
+ return super (ExampleSerializer , self ).retrieve (self , request )
71
+
60
72
@list_route ()
61
73
def custom_list_action (self , request ):
62
74
return super (ExampleViewSet , self ).list (self , request )
@@ -174,6 +186,17 @@ def test_authenticated_request(self):
174
186
coreapi .Field ('d' , required = False , location = 'form' , schema = coreschema .String (title = 'D' )),
175
187
]
176
188
),
189
+ 'custom_action_with_list_fields' : coreapi .Link (
190
+ url = '/example/{id}/custom_action_with_list_fields/' ,
191
+ action = 'post' ,
192
+ encoding = 'application/json' ,
193
+ description = 'A custom action using both list field and list serializer in the serializer.' ,
194
+ fields = [
195
+ coreapi .Field ('id' , required = True , location = 'path' , schema = coreschema .String ()),
196
+ coreapi .Field ('a' , required = True , location = 'form' , schema = coreschema .Array (title = 'A' , items = coreschema .Integer ())),
197
+ coreapi .Field ('b' , required = True , location = 'form' , schema = coreschema .Array (title = 'B' , items = coreschema .String ())),
198
+ ]
199
+ ),
177
200
'custom_list_action' : coreapi .Link (
178
201
url = '/example/custom_list_action/' ,
179
202
action = 'get'
0 commit comments