Ожидался экземпляр Django, получен OrderedDict
Пытаюсь вручную обработать данные Model и вернуть клиенту, возникла ошибка - TypeError: ожидался экземпляр 'Location', получен OrderedDict
class ParticipantViewSet(viewsets.ModelViewSet):
def retrieve(self, request, pk=None):
queryset = Participant.objects.all().prefetch_related("locations")
user = get_object_or_404(queryset, pk=pk)
serializer = ParticipantSerializer(user)
locations = serializer.data["locations"]
specialLocationList = locations
index = 0
for location in locations:
## change location properties
specialLocationList[index] = location
index += 1
user.locations.set(specialLocationList)
return JsonResponse(user, safe=False)