fixed similar establishments
This commit is contained in:
parent
90c9e321f7
commit
8766388256
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user