[Fixed]-Serializing GeoQuerySet

1👍

Problem is inner “serialization” process. Actually it’s implemented using deserialization pattern which doesn’t work of course. It should look something like this:

    def post(self, request, *args, **kwargs):
    serializer = self.serializer_class(data=request.data)
    if serializer.is_valid():
        point = Point(float(request.data['latitude']), float(request.data['longitude']))
        events = Event.objects.filter(location_point__distance_lte=(point, D(km=int(request.data['distance']))))
        if events.exists():
            event_serializer = self.get_event_serializer()
            ev = event_serializer(events, many=True)
            return Response(ev.data, status=status.HTTP_200_OK)
        return Response(status=status.HTTP_400_BAD_REQUEST)
    return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
👤jtiai

0👍

ev = event_serializer(data=events) should be

ev = event_serializer(data=events,many=True)

👤levi

Leave a comment