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

functional API, minimum viable (though largely irl useless) product

parent 0264d7e6
# standard library imports
from __future__ import absolute_import, print_function
# third party imports
from rest_framework import serializers
# imports from your apps
from housing.models import Building, Floor, Room
class BuildingSerializer(serializers.ModelSerializer):
class Meta:
model = Building
fields = ('name', 'neighbourhood', 'campus')
class FloorSerializer(serializers.ModelSerializer):
class Meta:
model = Floor
fields = ('number', )
class RoomSerializer(serializers.ModelSerializer):
class Meta:
model = Room
fields = ('number', )
# standard library imports
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
router = DefaultRouter()
router.register(r'buildings', BuildingAPI)
router.register(r'floors', FloorAPI)
router.register(r'rooms', RoomAPI)
urlpatterns = router.urls
# standard library imports
from __future__ import absolute_import, print_function
# third party imports
from rest_framework.viewsets import ReadOnlyModelViewSet
# imports from your apps
from housing.models import Building, Floor, Room
from .serializers import BuildingSerializer, FloorSerializer, RoomSerializer
class BuildingAPI(ReadOnlyModelViewSet):
queryset = Building.objects.all()
serializer_class = BuildingSerializer
class FloorAPI(ReadOnlyModelViewSet):
queryset = Floor.objects.all()
serializer_class = FloorSerializer
class RoomAPI(ReadOnlyModelViewSet):
queryset = Room.objects.all()
serializer_class = RoomSerializer
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