GeoDjango,基于数据库列的距离过滤器考虑了搜索者和他正在寻找的人的半径

GeoDjango, distance filter based on database column taking into account the radius of both the seeker and the one he is looking for

我需要在寻找目标时同时考虑搜索者和他正在寻找的目标的半径。我该怎么做?

现在我可以从导引头端过滤:

n_range = Obj.objects.filter(location__distance_lt=(
                       obj.location, Distance(mi=obj.radius)
                    )
                )

这是我的模型:

class Obj(models.Model):
    RADIUS_CHOICES = [
        (1, "1 km round"),
        (2, "2 km round"),
        (3, "3 km round"),
    ]
    radius = models.PositiveIntegerField(
        default=RADIUS_CHOICES[0][0],
        choices=RADIUS_CHOICES
    )
  location = models.PointField(null=True, blank=True)

需要的是,最终的结果应该只有那些落入求道者半径内的物体,同时求道者也必须落入他所求者的半径内

from django.contrib.gis.measure import D
from django.contrib.gis.db.models.functions import Distance

obj = Obj.objects.get(id=1)
in_rande = Obj.objects.filter(
    location__distance_lte=(
        obj.location, D(mi=obj.radius)
    )).annotate(
        distance=Distance('location', profile.location)
    ).values('id', 'distance', 'radius')
relevant_ids = [i['id'] for i in in_rande if i['radius'] > i['distance'].km]