0

I am working on DRF to build an API:

serializers.py:

class TemplateSerializer(FilterSerializerByOrgOwned, ValidatedModelSerializer):
    class Meta():
        model = Template
        fields = '__all__'

views.py:

class TemplateListCreateView(ListCreateAPIView):
    serializer_class = TemplateSerializer
    queryset = Template.objects.all()
    pagination_class = ListViewPagination

I am getting the output as such: Output:

        {
            "id": "47fc6a80-70c2-4a08-9343-0e788812de5f",
            "created": "2021-02-23T15:28:24.466906+01:00",
            "modified": "2021-02-23T15:34:03.568730+01:00",
            "name": "TemplateOne",
            "config": "OrderedDict([('general', OrderedDict([('timezone', 'Indian/Maldives'), ('maintainer', 'ManishtempOne'), ('description', 'Hey I am the tester of templateOne')]))])",
            "organization": "7f5e09e8-8ae7-42dd-8d83-c36080af7b05",

        },

In the above output, I have a field config which is displayed in a simple manner, I want to display that field in a JSON format. I tried different approaches found on StackOverflow, but didn't work for me. Is there any way out?

The config field is:

    config = JSONField(
        _('configuration'),
        default=dict,
        help_text=_('configuration in NetJSON DeviceConfiguration format'),
        load_kwargs={'object_pairs_hook': collections.OrderedDict},
        dump_kwargs={'indent': 4},
    )
Manish Shah
  • 331
  • 5
  • 18

0 Answers0