Django filter query

I’m trying to implement filter based on request.user latitude and longitude and other users in database, but don’t know how to correctly write a query. I’m not using GeoDjango, instead for distance calculations I’m using geopy distance.distance() function.

I tried to do something like this but it doesn’t work:

class Distance(Func):
    function = distance.distance().km
class ClientFilter(filters.FilterSet):
    distance = filters.NumberFilter(
  def get_distance(self, queryset, name, value):
        if not value:
            return queryset
        lat_1 = self.request.user.latitude
        lon_1 = self.request.user.longitude
        return queryset.annotate(dist=Distance(lat_1, lon_1, F('latitude'), F('longitude'))).filter(dist__lte=value)