change ApartamentComparisonAPIView to ApartamentComparisonViewSet

This commit is contained in:
Денис Сарапулов 2023-05-07 20:42:06 +10:00
parent e7278bc378
commit 556c859753
2 changed files with 4 additions and 3 deletions

View File

@ -6,5 +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()) path("comparison/", views.ApartamentComparisonViewSet.as_view({'get': 'retrieve'})),
]) ])

View File

@ -12,6 +12,7 @@ class ApartamentViewSet(viewsets.ReadOnlyModelViewSet):
def get_queryset(self): def get_queryset(self):
apartaments = Apartament.objects.all() apartaments = Apartament.objects.all()
print(apartaments)
return apartaments return apartaments
def get_serializer_class(self): def get_serializer_class(self):
@ -21,9 +22,9 @@ class ApartamentViewSet(viewsets.ReadOnlyModelViewSet):
return ApartamentDetailSerializer return ApartamentDetailSerializer
class ApartamentComparisonAPIView(APIView): class ApartamentComparisonViewSet(viewsets.ReadOnlyModelViewSet):
"""Вывод отдельных квартир для сравнения""" """Вывод отдельных квартир для сравнения"""
def get(self, request): def retrieve(self, request, *args, **kwargs):
apartaments_id = request.COOKIES["apartament_comparison_id"].split(',') # получение куки пример (123,453) apartaments_id = request.COOKIES["apartament_comparison_id"].split(',') # получение куки пример (123,453)
apartaments = [] apartaments = []
for i in apartaments_id: for i in apartaments_id: