class ItemListView(ListCreateAPIView):
model = Item
serializer_class = ItemSerializer # model serializer
def get_queryset(self):
return self.model.objects.all()
def get(self, request, *args, **kwargs):
return self.list(request, *args, **kwargs)
是否有机会通过get
方法向JSON响应中添加其他数据?
答案 0 :(得分:2)
您可以覆盖ItemSerializer
的{{1}}方法,如
to_representation()
答案 1 :(得分:0)
response = self.list(..)
response.data['hello'] = 'world'
return response