fixed similar establishments

This commit is contained in:
Anatoly 2019-09-25 13:16:02 +03:00
parent 90c9e321f7
commit 8766388256
2 changed files with 6 additions and 6 deletions

View File

@ -128,10 +128,11 @@ class EstablishmentQuerySet(models.QuerySet):
output_field=models.FloatField()
))
def similar(self, establishment_slug: str):
def similar(self, establishment_slug: str, output_objects: int = 12):
"""
Return QuerySet with objects that similar to Establishment.
:param establishment_slug: str Establishment slug
:param output_objects: int of output objects
"""
establishment_qs = Establishment.objects.filter(slug=establishment_slug,
public_mark__isnull=False)
@ -145,7 +146,9 @@ class EstablishmentQuerySet(models.QuerySet):
public_mark__gte=10) \
.annotate_distance(point=establishment.address.coordinates) \
.annotate_intermediate_public_mark() \
.annotate_mark_similarity(mark=establishment.public_mark)
.annotate_mark_similarity(mark=establishment.public_mark) \
.order_by('distance') \
.order_by('mark_similarity')[:output_objects]
else:
return self.none()

View File

@ -30,10 +30,7 @@ class EstablishmentSimilarListView(EstablishmentListView):
def get_queryset(self):
"""Override get_queryset method"""
number_objects = 12 # Count of similar objects
return super().get_queryset().similar(establishment_slug=self.kwargs.get('slug')) \
.order_by('distance')[:number_objects * 3] \
.order_by('mark_similarity')[:number_objects]
return super().get_queryset().similar(establishment_slug=self.kwargs.get('slug'))
class EstablishmentRetrieveView(EstablishmentMixin, generics.RetrieveAPIView):