Verified Commit 4ca79e19 authored by David Haynes's avatar David Haynes 🙆
Browse files

Comment up serializers.py

- really simple since everything is basically ModelSerializers
parent c8abba16
"""
api/serializers.py
Rest Framework Serializers
Serializers allow complex data to be converted to native Python datatypes that
can then be easily rendered into JSON, XML or other content types.
http://www.django-rest-framework.org/api-guide/serializers
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
......@@ -13,46 +16,66 @@ from .models import Category, Facility, Schedule, OpenTime, Location
# Other Imports
from rest_framework import serializers
class OpenTimeSerializer(serializers.ModelSerializer):
class CategorySerializer(serializers.ModelSerializer):
"""
Serializer for the Category model.
"""
class Meta:
model = OpenTime
# Choose the model to be serialized
model = Category
# Serialize all of the fields
fields = '__all__'
class CategorySerializer(serializers.ModelSerializer):
class LocationSerializer(serializers.ModelSerializer):
"""
Serializer for the Location model.
"""
class Meta:
model = Category
# Choose the model to be serialized
model = Location
# Serialize all of the fields
fields = '__all__'
class LocationSerializer(serializers.ModelSerializer):
class OpenTimeSerializer(serializers.ModelSerializer):
"""
Serializer for the OpenTime model.
"""
class Meta:
model = Location
# Choose the model to be serialized
model = OpenTime
# Serialize all of the fields
fields = '__all__'
class ScheduleSerializer(serializers.ModelSerializer):
"""
Serializer for the Schedule model.
"""
# Append a serialized OpenTime object
open_times = OpenTimeSerializer(many=True, read_only=True)
class Meta:
# Choose the model to be serialized
model = Schedule
# List the fields that we are serializing
fields = ('id', 'open_times', 'modified', 'name', 'valid_start',
'valid_end')
class FacilitySerializer(serializers.HyperlinkedModelSerializer):
"""
Serializer for the Facility model.
"""
# Append a serialized Category object
facility_category = CategorySerializer(many=False, read_only=True)
# Append a serialized Location object
facility_location = LocationSerializer(many=False, read_only=True)
# Append a serialized Schedule object to represent main_schedule
main_schedule = ScheduleSerializer(many=False, read_only=True)
# Append a serialized Schedule object to represent special_schedules
special_schedules = ScheduleSerializer(many=True, read_only=True)
class Meta:
# Choose the model to be serialized
model = Facility
# List the fields that we are serializing
fields = ('id', 'facility_category', 'facility_location',
'main_schedule', 'special_schedules', 'modified', '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