I used ModelViewSet, my question is, different operations return different fields, how to do it? The two actions, Retrieve and List, return different fields.

38 views
Skip to first unread message

印海天

unread,
Jun 14, 2022, 11:21:26 AM6/14/22
to Django REST framework

截图_选择区域_20220614222038.png

Santosh Rana

unread,
Jun 15, 2022, 12:13:49 AM6/15/22
to django-res...@googlegroups.com
#Add the this method inside your viewset
def get_serializer_class(self):
if self.action == 'retrieve':
return Your_Retrive_Serializer
else:
return self.serializer_class

On Tue, Jun 14, 2022 at 9:06 PM 印海天 <goo...@gmail.com> wrote:

截图_选择区域_20220614222038.png

--
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-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/5d1e6b72-30b9-440e-99f2-a8bfb99c0e83n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages