Добавлена выдача по точкам на карте

main
through-your-tears 9 months ago
parent 706e87ddec
commit e08bcca606

@ -1,3 +1,5 @@
from django.contrib.gis.geos import Polygon
from .models import Category, Location, Organization, OrganizationImage, Region
from core.repositories import BaseRepository, ObjectDoesNotExist
@ -38,6 +40,15 @@ class OrganizationRepository(BaseRepository):
def get_by_category(cls, category_id):
return cls.model.objects.filter(category__pk=category_id)
@classmethod
def get_by_categories(cls, categories):
return cls.model.objects.filter(category__pk__in=categories)
@classmethod
def get_for_map(cls, categories, coords1, coords2):
rectangle = Polygon.from_bbox((*coords1, *coords2))
return cls.get_by_categories(categories).filter(location__within=rectangle)
class OrganizationImagesRepository(BaseRepository):
model = OrganizationImage

@ -61,6 +61,19 @@ class OrganizationSearchListAPIView(ListAPIView):
return super().list(request, args, kwargs)
class OrganizationMapFilter(ListAPIView):
serializer_class = OrganizationListSerializer
def get_queryset(self):
ids = list(map(int, self.request.query_params.get('id')))
coords1 = (float(self.request.query_params.get('lat1')), float(self.request.query_params.get('lon1')))
coords2 = (float(self.request.query_params.get('lat2')), float(self.request.query_params.get('lon2')))
if ids and coords1 and coords2:
return OrganizationRepository.get_for_map(ids, coords1, coords2)
else:
return OrganizationRepository.all()[:50]
class CategoryListAPIView(ListAPIView):
pagination_class = PageNumberPagination
queryset = CategoryRepository.all()

Loading…
Cancel
Save