Django RestFramework - convert list to dict

I'm translating an API in Java to DRF and the consumption will be in a data.py

Using DRF API
ind = requests.get(base_url + "get_ind?ind_id={}".format(ind))
print(ind.json())
[{ "id": 1, "ind_id": 1, "co_ind": "Some String", "no_ind": "Some String", "ds_ind": "Some String", "ds_not_ind": "", "uni_id": 1, "per_id": [ { "id": 7, "no_per": "Some String", "tip_var": "", "co_per": "Some String", "no_cat": "", "per_id": 7, "uni_id": 1 }, { "id": 9, "no_per": "Some String", "tip_var": "", "co_per": "Some String", "no_cat": "", "per_id": 9, "uni_id": 1 }, ], "co_mod": "Some String" }]

I want:

Using Java API
ind = requests.get(base_url + "get_ind?ind_id={}".format(ind))
print(ind.json())
{ "id": 1, "ind_id": 1, "co_ind": "A", "no_ind": "DOMÍCILIOS QUE POSSUEM EQUIPAMENTO TIC", "ds_ind": "Total de domicílios", "ds_not_ind": "", "uni_id": 1, "per_id": [ { "id": 7, "no_per": "Proporção de domicílios que possuem equipamentos TIC", "tip_var": "", "co_per": "DIC_TV", "no_cat": "", "per_id": 7, "uni_id": 1 }, { "id": 9, "no_per": "Proporção de domicílios que possuem equipamentos TIC", "tip_var": "", "co_per": "DIC_RADIO", "no_cat": "", "per_id": 9, "uni_id": 1 }, ], "co_mod": "A" }

This is the view.py:

class GetIndFilter(SearchFilter):
    def filter_queryset(self, request, queryset, view):
        queryset = super().filter_queryset(request, queryset, view)
        ind_id = request.GET.get('ind_id')
        
        if(ind_id != ''):
            result = Inds.objects.filter(ind_id = ind_id)
            return result

class GetIndViewSet(viewsets.ModelViewSet):
    queryset = Inds.objects.all()
    serializer_class = IndsSerializer
    filter_backends = [GetIndFilter]
    filterset_fields = ['ind_id']
def toDict(list):
    dict = {}
    for item in list:
        dict.update(item)
    return dict

ind = toDict(ind.json())
Back to Top