Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hunter T Jozwiak
whats-open
Commits
4ca79e19
Verified
Commit
4ca79e19
authored
May 29, 2017
by
David Haynes
🙆
Browse files
Comment up serializers.py
- really simple since everything is basically ModelSerializers
parent
c8abba16
Changes
1
Hide whitespace changes
Inline
Side-by-side
whats-open/api/serializers.py
View file @
4ca79e19
"""
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
OpenTime
Serializer
(
serializers
.
ModelSerializer
):
class
Category
Serializer
(
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
Category
Serializer
(
serializers
.
ModelSerializer
):
class
Location
Serializer
(
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
Location
Serializer
(
serializers
.
ModelSerializer
):
class
OpenTime
Serializer
(
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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment