[Answered ]-Custom DRF list function not returning some of the dict key/value pairs

2👍

You can add pagination

def list(self, request):
    loc = Location.objects.filter(user=request.user).latest('timestamp')
    nearby = loc.get_near()  # returns a list with dicts that contain user and dist

    nearby_users = [n['user'] for n in nearby]  # gets a list of users

    # start pagination
    page = self.paginate_queryset(nearby_users)
    if page is not None:
        serializer = self.get_serializer(page, many=True)
        return self.get_paginated_response(serializer.data)
    # end pagination

    serializer = self.get_serializer(nearby_users, many=True)

    return Response(serializer.data)

more details in super mixins from line 39

Leave a comment