Hi. 

This approach isn’t going to work with ViewSets. As you have seen, ManualSchema 
will be applied to each route, with no ability to scope per-action. (This is 
more a problem with ViewSets than anything else…)

Instead you need to subclass either ManualSchema or AutoSchema and override 
`get_link` (or for AutoSchema maybe `get_manual_fields`) to inspect 
`self.view.action`, and provide the appropriate fields. 

Something like: 

if self.view.action == ‘list’:
    # … create the fields for the list action…
else:
   # … create the fields for read action...

I hope that helps. 

Regards,

Carlton

> On 31 Jan 2018, at 15:09, 秦斌 <jus...@gmail.com <mailto:jus...@gmail.com>> 
> wrote:
> 
> 
> I mean document is like this with visit http://127.0.0.1/docs/ 
> <http://127.0.0.1/docs/>
> 
>  
> <https://lh3.googleusercontent.com/-LrwUAsXXQ6M/WnHNdxgmttI/AAAAAAAACgE/4fPt2BedP8ESh_zi4dNcyARKn_QsGf5DgCLcBGAs/s1600/BaiduShurufa_2018-1-31_22-6-32.png>
> 
> 
> 
> this is my code about the document
> 
> class GoodsViewSet(viewsets.ReadOnlyModelViewSet):
>     schema = ManualSchema(fields=[
>         coreapi.Field(
>             name="type_id",
>             # ['name', 'required', 'location', 'schema', 'description', 
> 'type', 'example']
>             required=False,
>             location="query",
>             # schema=coreschema.Integer(minimum=1, maximum=20),
>             description ="1 : fuirt  2 : seafood  3 : meat 4 : eggs 5 some 
> else :  6 : freezen",
>         ),
>         coreapi.Field(
>             "limit",
>             required=False,
>             location="query",
>             schema=coreschema.Integer(minimum=1, maximum=20)
>         ),
>     ]
>     )
> 
> I try to add description to coreapi.Field , but it does not works. and both 
> 'type_id' and 'limit' are show in list and read. I just want to show them in 
> list
> 
> 
> 
> I read the document of restful django. but i don't know  how to add document 
> to ViewSet
> 
> I read flowing doc
> http://www.django-rest-framework.org/api-guide/schemas/#examples 
> <http://www.django-rest-framework.org/api-guide/schemas/#examples>
> http://www.django-rest-framework.org/api-guide/schemas/#manualschema 
> <http://www.django-rest-framework.org/api-guide/schemas/#manualschema>
> 
> all I got is not suitable to ViewSet. they are suitable for View.
> 
> Who can give me a example code to document a ViewSet. Thanks for help. Sorry 
> for poor English.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django REST framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-rest-framework+unsubscr...@googlegroups.com 
> <mailto:django-rest-framework+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to