{"action":"opened","issue":{"url":"https://api.github.com/repos/djangonauts/django-rest-framework-gis/issues/103","repository_url":"https://api.github.com/repos/djangonauts/django-rest-framework-gis","labels_url":"https://api.github.com/repos/djangonauts/django-rest-framework-gis/issues/103/labels{/name}","comments_url":"https://api.github.com/repos/djangonauts/django-rest-framework-gis/issues/103/comments","events_url":"https://api.github.com/repos/djangonauts/django-rest-framework-gis/issues/103/events","html_url":"https://github.com/djangonauts/django-rest-framework-gis/issues/103","id":145188542,"number":103,"title":"Duplicate Results for ManyToMany field with DistanceToPointFilter","user":{"login":"egamonal","id":1971675,"avatar_url":"https://avatars.githubusercontent.com/u/1971675?v=3","gravatar_id":"","url":"https://api.github.com/users/egamonal","html_url":"https://github.com/egamonal","followers_url":"https://api.github.com/users/egamonal/followers","following_url":"https://api.github.com/users/egamonal/following{/other_user}","gists_url":"https://api.github.com/users/egamonal/gists{/gist_id}","starred_url":"https://api.github.com/users/egamonal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/egamonal/subscriptions","organizations_url":"https://api.github.com/users/egamonal/orgs","repos_url":"https://api.github.com/users/egamonal/repos","events_url":"https://api.github.com/users/egamonal/events{/privacy}","received_events_url":"https://api.github.com/users/egamonal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-04-01T14:01:20Z","updated_at":"2016-04-01T14:01:20Z","closed_at":null,"body":"A year ago a similar issue was filled for Django framework https://github.com/tomchristie/django-rest-framework/issues/1488\r\n\r\nModel example:\r\n```\r\n\r\nclass PointOfSales(models.Model):\r\n    location = models_gis.PointField(blank=True, null=True)\r\n\r\nclass Deal(models.Model):\r\n    promo_code = models.CharField(max_length=25, blank=True, null=True)\r\n    points_of_sales = models.ManyToManyField(PointOfSales, related_name='deals')\r\n```\r\n\r\nI wanted to filter deals in points of sales near me:\r\n\r\n````\r\nclass DealViewSet(viewsets.ReadOnlyModelViewSet):\r\n    serializer_class = DealSerializer\r\n    queryset = Deal.objects.all()\r\n    filter_backends = (DistanceToPointFilter, )\r\n    distance_filter_field = 'points_of_sales__location'\r\n    distance_filter_convert_meters = True # by default we use srid=4326 (uses degrees), but input should be in meters\r\n```\r\n\r\nA deal in two points of sales near me will end up twice in the response.\r\n\r\nIn /rest_framework_gis/filters.py there is a `filter_queryset` method where I added `.distinct()` just like in the PR that fixed restframework https://github.com/tomchristie/django-rest-framework/pull/2535/commits/3522b69394d932c8bf8028a456b6d9b64c38b54e and I got the expected result. I didn't break any other of my tests. Might it be a fix?\r\n\r\n````\r\n    def filter_queryset(self, request, queryset, view):\r\n        # ...\r\n        return queryset.filter(Q(**{'%s__%s' % (filter_field, geoDjango_filter): (point, dist)})).distinct()\r\n```"}}