Commit af87d164 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

significantish progress towards returning stuff on a specific instance rather...

significantish progress towards returning stuff on a specific instance rather than just listing everything... aka irl usefulness
parent 4258875b
......@@ -11,9 +11,6 @@ from accounts.models import Major
class BuildingSerializer(serializers.ModelSerializer):
# floors
# rooms
class Meta:
model = Building
fields = ('name', 'neighbourhood', 'campus')
......@@ -22,7 +19,6 @@ class BuildingSerializer(serializers.ModelSerializer):
class FloorSerializer(serializers.ModelSerializer):
building = serializers.SerializerMethodField('get_building_name')
#rooms = serializers.SerializerMethodField('get_floor_rooms')
def get_building_name(self, floor):
return floor.building.name
......@@ -34,7 +30,7 @@ class FloorSerializer(serializers.ModelSerializer):
class Meta:
model = Floor
fields = ('number', 'building', )#'rooms')
fields = ('number', 'building')
class RoomSerializer(serializers.ModelSerializer):
......
......@@ -2,16 +2,27 @@
from __future__ import absolute_import, print_function
# core django imports
from django.conf.urls import patterns, include, url
# third party imports
from rest_framework.routers import DefaultRouter
# imports from your apps
from .views import BuildingAPI, FloorAPI, RoomAPI, MajorAPI
from .views import BuildingList, BuildingRetrieve, FloorRetrieve, RoomRetrieve,\
MajorList, MajorRetrieve
# custom routing ftw
# separate out major and building patterns
building_urls = patterns('',
url(r'^$', BuildingList.as_view(), name='api_list_buildings'),
url(r'^building/(?P<pk>\d+)/$', BuildingRetrieve.as_view(), name='api_detail_building'),
url(r'^building/floor/(?P<pk>\d+)/$', FloorRetrieve.as_view(), name='api_detail_floor'),
# list all the floors still?
url(r'^building/floor/room/(?P<pk>\d+)/$', RoomRetrieve.as_view(), name='api_deatil_room'),
# list all the rooms still?
)
router = DefaultRouter()
router.register(r'buildings', BuildingAPI)
router.register(r'floors', FloorAPI)
router.register(r'rooms', RoomAPI)
router.register(r'majors', MajorAPI)
major_urls = patterns('',
url(r'^$', MajorList.as_view(), name='api_list_majors'),
url(r'^(?P<pk>\d+)/$', MajorRetrieve.as_view(), name='api_detail_building'),
)
urlpatterns = router.urls
urlpatterns = patterns('',
url(r'^housing/', include(building_urls)),
url(r'^majors/', include(major_urls)),
)
# standard library imports
from __future__ import absolute_import, print_function
# third party imports
from rest_framework.viewsets import ReadOnlyModelViewSet
from rest_framework.pagination import PageNumberPagination
from rest_framework.generics import ListAPIView, RetrieveAPIView
# imports from your apps
from housing.models import Building, Floor, Room
from accounts.models import Major
......@@ -10,30 +10,58 @@ from .serializers import (BuildingSerializer, FloorSerializer, RoomSerializer,
MajorSerializer)
# pagination class for optional inheritance
class HousingPagination(PageNumberPagination):
page_size = 25
page_size = 50
page_size_query_param = 'page_size'
max_page_size = 1000
class BuildingAPI(ReadOnlyModelViewSet):
# the actual api views
# housing apis
class BuildingList(ListAPIView):
queryset = Building.objects.all()
serializer_class = BuildingSerializer
pagination_class = HousingPagination
class FloorAPI(ReadOnlyModelViewSet):
class BuildingRetrieve(RetrieveAPIView):
model = Building
queryset = Building.objects.all()
serializer_class = BuildingSerializer
#class FloorList(ListAPIView):
# queryset = Floor.objects.all()
# serializer_class = FloorSerializer
# pagination_class = HousingPagination
class FloorRetrieve(RetrieveAPIView):
model = Floor
queryset = Floor.objects.all()
serializer_class = FloorSerializer
pagination_class = HousingPagination
class RoomAPI(ReadOnlyModelViewSet):
class RoomRetrieve(RetrieveAPIView):
model = Room
queryset = Room.objects.all()
serializer_class = RoomSerializer
pagination_class = HousingPagination
class MajorAPI(ReadOnlyModelViewSet):
#class RoomList(ListAPIView): # kek
# queryset = Room.objects.all()
# serializer_class = RoomSerializer
# pagination_class = HousingPagination
# major apis
class MajorList(ListAPIView):
queryset = Major.objects.all()
serializer_class = MajorSerializer
class MajorRetrieve(RetrieveAPIView):
model = Major
queryset = Major.objects.all()
serializer_class = MajorSerializer
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment