我已经设置了我的urls.py
和Views.py
文件,以两种不同的方式序列化我的项目模型:用于"检索"操作的详细信息和用于"列表"操作的简短信息.
到目前为止,这个方法运行得很好:
/projects/ = list of projects with abbreviated information
/projects/12 = detailed information about a specific project (id=12)
Urls.py:
router.register(r'projects', ProjectViewSet, basename='project')
Views.py
class ProjectViewSet(viewsets.ModelViewSet):
serializer_class = ProjectSerializerMini
# Select a serializer according to the action (i.e.: 'retrieve' will
# return a more detailed serialized data than 'list')
action_serializers = {
'retrieve': ProjectSerializerDetail,
'list': ProjectSerializerList
}
def get_serializer_class(self):
return self.action_serializers.get(self.action, self.serializer_class)
我的问题是:是否有可能使用ViewSet框架调用第三个序列化程序,该序列化程序将返回even more detailed组信息.
例:/projects/12/extradetail
这样做的原因是,其中一些记录包括相当大量的地理空间数据.我只想在某些情况下检索这个额外的详细信息