From a25d8460285a4f4e78e3fc66005f4b044b16f4c4 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 10 Oct 2019 21:02:56 +0300 Subject: [PATCH] fixed bug with duplicated records in similar establishments --- apps/establishment/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/establishment/models.py b/apps/establishment/models.py index 5290f368..1ff82e72 100644 --- a/apps/establishment/models.py +++ b/apps/establishment/models.py @@ -14,8 +14,8 @@ from django.utils.translation import gettext_lazy as _ from phonenumber_field.modelfields import PhoneNumberField from collection.models import Collection -from main.models import Award, MetaDataContent from location.models import Address +from main.models import Award, MetaDataContent from review.models import Review from utils.models import (ProjectBaseMixin, TJSONField, URLImageMixin, TranslatedFieldsMixin, BaseAttributes) @@ -180,7 +180,8 @@ class EstablishmentQuerySet(models.QuerySet): return self.filter(id__in=subquery_filter_by_distance) \ .annotate_intermediate_public_mark() \ .annotate_mark_similarity(mark=establishment.public_mark) \ - .order_by('mark_similarity') + .order_by('mark_similarity') \ + .distinct('mark_similarity', 'id') else: return self.none()