由于您似乎正在使用Rest框架中的ListView之一,因此可以覆盖类中的list()方法并在结果数据上设置新值,如下所示:
def list(self, request, *args, **kwargs): response = super().list(request, args, kwargs) # Add data to response.data Example for your object: response.data['10_mi_count'] = 10 # Or wherever you get this values from response.data['20_mi_count'] = 30 response.data['30_mi_count'] = 45 return response
请注意,您的类必须直接或通过Rest framework API(http://www.django-rest-framework.org/api-
guide/generic-views#listmodelmixin)的GenericView继承ListModelMixin
。我真的不知道这是否是正确的方法,但这是一个快速解决方案。
希望能帮助到你!



