From 76321d4306c6593751f06dcd8d4cd7f9c2670189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B5=D0=BD=D0=B8=D1=81=20=D0=A1=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=BF=D1=83=D0=BB=D0=BE=D0=B2?= Date: Sun, 7 May 2023 19:48:53 +1000 Subject: [PATCH] made API for comparison --- pairent_backend/pairent_app/urls.py | 1 + pairent_backend/pairent_app/views.py | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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