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

begun fleshing out serializers, added major serializer

parent a0c6845a
# standard library imports
from __future__ import absolute_import, print_function
# core django imports
from django.core.serializers import serialize
# third party imports
from rest_framework import serializers
# imports from your apps
from housing.models import Building, Floor, Room
from accounts.models import Major
class BuildingSerializer(serializers.ModelSerializer):
# floors
# rooms
class Meta:
model = Building
fields = ('name', 'neighbourhood', 'campus')
......@@ -15,13 +21,40 @@ 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
def get_floor_rooms(self, floor):
rooms = serialize('json', Room.objects.filter(floor=floor),
fields=('number'))
return rooms
class Meta:
model = Floor
fields = ('number', )
fields = ('number', 'building', )#'rooms')
class RoomSerializer(serializers.ModelSerializer):
building = serializers.SerializerMethodField('get_building_name')
floor = serializers.SerializerMethodField('get_floor_number')
def get_building_name(self, room):
return room.floor.building.name
def get_floor_number(self, room):
return room.floor.number
class Meta:
model = Room
fields = ('number', )
fields = ('number', 'floor', 'building')
class MajorSerializer(serializers.ModelSerializer):
class Meta:
model = Major
fields = ('name', )
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