19 lines
630 B
Python
19 lines
630 B
Python
from rest_framework import viewsets
|
|
|
|
from .models import Apartament
|
|
from .serializer import (ApartamentListSerializer,
|
|
ApartamentDetailSerializer)
|
|
|
|
|
|
class ApartamentViewSet(viewsets.ReadOnlyModelViewSet):
|
|
"""Вывод списка квартир или отдельной квартиры"""
|
|
|
|
def get_queryset(self):
|
|
apartaments = Apartament.objects.all()
|
|
return apartaments
|
|
|
|
def get_serializer_class(self):
|
|
if self.action == 'list':
|
|
return ApartamentListSerializer
|
|
elif self.action == "retrieve":
|
|
return ApartamentDetailSerializer |