【问题标题】:Searching points inside certain radius在一定半径内搜索点
【发布时间】:2013-04-30 09:16:42
【问题描述】:

我有以下 Point 模型:

class Point(models.Model):
    name = CharField(max_length=50)
    location = PointField()

我现在正在尝试获取距离该点 5 公里的所有点:

points = Point.objects.filter(location__dwithin=(point.location, D(km=5)))

然后我收到以下错误: FieldError:不允许加入字段“位置”。您是否拼错了查找类型的“dwithin”?

【问题讨论】:

    标签: django postgis geodjango


    【解决方案1】:

    发现问题 - RTFM。每个模型都需要以下字段:

     objects = models.GeoManager()
    

    【讨论】:

    • 在 Django 2 中,GeoManagerGeoQuerySet 类被删除(不赞成,AFAIK 不再需要它们)。参考。 2.0 release notes
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 2016-09-06
    • 2014-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多