from rest_framework.views import APIView from rest_framework.response import Response from .models import Apartament from .serializer import ApartamentListSerializer, ApartamentDetailSerializer class ApartamentListView(APIView): """Вывод списка квартир""" def get(self, request): apartaments = Apartament.objects.all() headers = {'total-count': len(apartaments)} serializer = ApartamentListSerializer(apartaments, many=True) return Response(serializer.data, headers=headers) class ApartamentDetailView(APIView): """Вывод квартиры""" def get(self, request, id): apartament = Apartament.objects.get(id=id) serializer = ApartamentDetailSerializer(apartament) return Response(serializer.data)