Currently, I have a ListAPIView that returns a list of object dictionaries:
[ { id: 1, ...}, { id: 2, ...}, ... ]
I would like to change
You can traverse each item and with a dict comprehension create your desired dictionary. For example:
>>> l = [{ "id": 1, "x": 4}, { "id": 2, "x": 3}] >>> {v["id"]: v for v in l} {1: {'x': 4, 'id': 1}, 2: {'x': 3, 'id': 2}}