1
我使用django-google-maps获取某个地点的位置。 在模型中,我有这个字段:Django按经度和纬度过滤后端过滤器
models.py
class PlaceLocation(models.Model):
name = models.CharField(max_length=200)
address = map_fields.AddressField(max_length=200)
geolocation = map_fields.GeoLocationField(max_length=100)
当我添加它可以自动找到这种格式的纬度和经度地址:44.4385334,26.005750199999966
我想使用Django过滤器后端按经度和纬度进行过滤,但我无法获取分隔的值。
filters.py
class LocationFilter(django_filters.FilterSet):
ids = NumberInFilter(name='id', lookup_expr='in')
geolocation = django_filters.NumberFilter(name='geolocation', lookup_expr='iexact')
如果我访问:
'http://127.0.0.1:8000/locations/places/' 它会告诉我所有的地方。
'http://127.0.0.1:8000/locations/places/?geolocation=44.4385334,26.005750199999966'它给了我一个空的列表。
我怎样才能分离值,以便我可以筛选这样的: “http://127.0.0.1:8000/locations/places/?lat=44.4385334&long=26.005750199999966”
这是一个有点很难给出一个正确的答案不知道是什么该查询集将最终看起来像。你能编辑你的问题来显示那个查询集是什么吗?例如'PlaceLocation.objects.filter(...)' – Sherpa