Open egamonal opened 8 years ago
In the meantime I extended the class in my filters.py
module
from rest_framework_gis.filters import DistanceToPointFilter
class DistanceToPointFilterDistinct(DistanceToPointFilter):
def filter_queryset(self, request, queryset, view):
return super(DistanceToPointFilterDistinct, self).filter_queryset(request, queryset, view).distinct()
Thanks for publishing your solution @egamonal. I'm not sure your solution can be applied as the general default case. Let's leave this issue open so if other people will encounter a similar problem we can continue the discussion.
A year ago a similar issue was filled for Django framework https://github.com/tomchristie/django-rest-framework/issues/1488
Model example:
I wanted to filter deals in points of sales near me:
A deal in two points of sales near me will end up twice in the response.
In /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?