legacy/pairent_backend/pairent_app/views.py

19 lines
630 B
Python
Raw Normal View History

from rest_framework import viewsets
2023-05-01 12:39:34 +02:00
from .models import Apartament
from .serializer import (ApartamentListSerializer,
ApartamentDetailSerializer)
2023-05-01 12:39:34 +02:00
class ApartamentViewSet(viewsets.ReadOnlyModelViewSet):
"""Вывод списка квартир или отдельной квартиры"""
2023-05-01 12:39:34 +02:00
def get_queryset(self):
2023-05-01 12:39:34 +02:00
apartaments = Apartament.objects.all()
return apartaments
def get_serializer_class(self):
if self.action == 'list':
return ApartamentListSerializer
elif self.action == "retrieve":
return ApartamentDetailSerializer