Django Rest Framework - Changing the labels of the fields

Viewed 1041

In Django Rest Framework, can we change the labels / names of the fields to more Human Readable format? For example, in below JSON data can we change the "mainline_revenue" to "Maineline Revenue" with space inside?

[{"mainline_revenue":18743.0,"regional_revenue":2914.0,"other_revenue":3198.0}]

Here is my serializing code:

serializers.py:

class FinancialDataSerializer(serializers.ModelSerializer):
    class Meta:
        fields = (
            'mainline_revenue',
            'regional_revenue',
            'other_revenue',
            )
        model = FinancialData

views.py:

class ChartData(generics.ListAPIView):
    serializer_class = FinancialDataSerializer

    def get_queryset(self, *args, **kwargs):
        airline_category = self.request.GET.get("airline_category")
        year_category = self.request.GET.get("year_category")
        queryset = FinancialData.objects.filter(airline_id=airline_category)
        queryset_filtered = queryset.filter(financial_year_id=year_category)
        return queryset_filtered
0 Answers
Related