2023-05-01 12:39:34 +02:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.response import Response
|
2023-04-10 09:34:57 +02:00
|
|
|
|
2023-05-01 12:39:34 +02:00
|
|
|
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)
|