django-rest-framework-gis icon indicating copy to clipboard operation
django-rest-framework-gis copied to clipboard

KeyError at /locationlist/ 'dwithin'

Open zshuang15 opened this issue 6 years ago • 1 comments

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,)

zshuang15 avatar Jan 17 '19 08:01 zshuang15

Hi! I'd be happy to take up this

krishnaglodha avatar Jul 12 '23 10:07 krishnaglodha