3

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
Hannan
  • 1,171
  • 6
  • 20
  • 39
  • What have you done to make that json? – binpy Aug 07 '17 at 22:57
  • @SancaKembang I have updated my question with the code to serialize data. Thanks – Hannan Aug 07 '17 at 23:42
  • I suggest you to following this similiar issue: https://stackoverflow.com/a/28200902/6396981, you can modify the `json_data` using `serializers.Field`. – binpy Aug 08 '17 at 02:24

0 Answers0