-
Notifications
You must be signed in to change notification settings - Fork 208
Open
Labels
Description
When I tried to use DistanceToPointFilter
to filter through distance, I got the issue that there is a KeyError about dwithin
.
models.py
class Location(models.Model):
user = models.ForeignKey('UserProfile', null=True, blank=True, on_delete=models.CASCADE)
address = models.CharField(max_length=255)
number = models.CharField(max_length=255)
city = models.CharField(max_length=100)
state = models.CharField(max_length=100)
zipcode = models.CharField(max_length=5)
# point = gis_models.PointField()
geometry = gis_models.GeometryField()
class Meta:
verbose_name = 'Location'
verbose_name_plural = 'Locations'
def __str__(self):
return self.geometry
serializers.py
class LocationSerializer(GeoFeatureModelSerializer):
class Meta:
model = Location
geo_field = 'geometry'
fields = "__all__"
views.py
class LocationListViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):
queryset = Location.objects.all()
serializer_class = LocationSerializer
distance_filter_convert_meters = True
distance_filter_field = 'geometry'
filter_backends = (DistanceToPointFilter,)