DRF-ModelViewSet 根据条件选择序列化
再用django写后台时候,restframework省去了很多事情,在这里记录一下如何根据不同的请求来获取不同的序列化,留给自己以后使用。
查看DRF ModelViewSet的源码,在GenericAPIView中写了获取序列化的方法。
class GenericAPIView(views.APIView):
# ...
def get_serializer_class(self):
"""
Return the class to use for the serializer.
Defaults to using `self.serializer_class`.
You may want to override this if you need to provide different
serializations depending on the incoming request.
(Eg. admins get full serializati