diff --git a/pairent_backend/pairent_app/urls.py b/pairent_backend/pairent_app/urls.py index 11ed44e..9924d44 100644 --- a/pairent_backend/pairent_app/urls.py +++ b/pairent_backend/pairent_app/urls.py @@ -6,4 +6,5 @@ from . import views urlpatterns = format_suffix_patterns([ path("apartaments/", views.ApartamentViewSet.as_view({'get': 'list'})), path("apartament//", views.ApartamentViewSet.as_view({'get': 'retrieve'})), + path("comparison/", views.ApartamentComparisonAPIView.as_view()) ]) diff --git a/pairent_backend/pairent_app/views.py b/pairent_backend/pairent_app/views.py index b3b4a21..c83530d 100644 --- a/pairent_backend/pairent_app/views.py +++ b/pairent_backend/pairent_app/views.py @@ -1,4 +1,6 @@ from rest_framework import viewsets +from rest_framework.response import Response +from rest_framework.views import APIView from .models import Apartament from .serializer import (ApartamentListSerializer, @@ -16,4 +18,14 @@ class ApartamentViewSet(viewsets.ReadOnlyModelViewSet): if self.action == 'list': return ApartamentListSerializer elif self.action == "retrieve": - return ApartamentDetailSerializer \ No newline at end of file + return ApartamentDetailSerializer + + +class ApartamentComparisonAPIView(APIView): + """Вывод отдельных квартир для сравнения""" + def get(self, request): + apartaments_id = request.COOKIES["apartament_comparison_id"].split(',') # получение куки пример (123,453) + apartaments = [] + for i in apartaments_id: + apartaments.append(ApartamentDetailSerializer(Apartament.objects.get(pk=i)).data) + return Response({"results": apartaments}) \ No newline at end of file