假设你有一个模型定义为
class Place(models.Model):
location = PointField()
你应该能够使用的within
查询检索与包含在用户提供的几何位置的所有地方
Place.objects.filter(location__within=geometry)
我建议你从前端将用户选择导出为GeoJSON并将POST
其导出到后端。在Django方面,你应该能够从提供的数据中创建一个GEOSGeometry
geometry = GEOSGeometry(request.POST['selection'])
Place.objects.filter(location__within=geometry)
你将要验证selection
有效的GeoJSON,但这至少应该使你入门。