made API for comparison
This commit is contained in:
parent
c6a4784cd2
commit
76321d4306
|
@ -6,4 +6,5 @@ from . import views
|
||||||
urlpatterns = format_suffix_patterns([
|
urlpatterns = format_suffix_patterns([
|
||||||
path("apartaments/", views.ApartamentViewSet.as_view({'get': 'list'})),
|
path("apartaments/", views.ApartamentViewSet.as_view({'get': 'list'})),
|
||||||
path("apartament/<int:pk>/", views.ApartamentViewSet.as_view({'get': 'retrieve'})),
|
path("apartament/<int:pk>/", views.ApartamentViewSet.as_view({'get': 'retrieve'})),
|
||||||
|
path("comparison/", views.ApartamentComparisonAPIView.as_view())
|
||||||
])
|
])
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from .models import Apartament
|
from .models import Apartament
|
||||||
from .serializer import (ApartamentListSerializer,
|
from .serializer import (ApartamentListSerializer,
|
||||||
|
@ -16,4 +18,14 @@ class ApartamentViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
if self.action == 'list':
|
if self.action == 'list':
|
||||||
return ApartamentListSerializer
|
return ApartamentListSerializer
|
||||||
elif self.action == "retrieve":
|
elif self.action == "retrieve":
|
||||||
return ApartamentDetailSerializer
|
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})
|
Loading…
Reference in New Issue