1
votes

I'm using django-google-maps to get the the location of a place. In models i have this field:

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)

When i add an address it automatically finds the latitude and longitude in this format: 44.4385334,26.005750199999966

I want to use django filter backend to filter by latitude and longitude, but i can't get the values separated.

filters.py

class LocationFilter(django_filters.FilterSet):
    ids = NumberInFilter(name='id', lookup_expr='in')
    geolocation = django_filters.NumberFilter(name='geolocation', lookup_expr='iexact')

If i access:

'http://127.0.0.1:8000/locations/places/' it will show me all the places.

'http://127.0.0.1:8000/locations/places/?geolocation=44.4385334,26.005750199999966' it's giving me an empty list.

How can i get the values separated so i can filter like this: 'http://127.0.0.1:8000/locations/places/?lat=44.4385334&long=26.005750199999966'

1
It's a little difficult to give a proper answer without knowing what the queryset will ultimately look like. Can you edit your question to show what that queryset would be? eg, PlaceLocation.objects.filter(...) - Sherpa

1 Answers

0
votes

In the end this worked:

class LocationFilter(django_filters.FilterSet):
    ids = NumberInFilter(name='id', lookup_expr='in')
    geolocation = django_filters.CharFilter(name='geolocation', lookup_expr='exact')

    class Meta:
        model = Location
        fields = ('ids', 'geolocation')