serializers.py 1.22 KB
Newer Older
1
2
3
4
5
6
7
8
# Future Imports
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)

# App Imports
from .models import Category, Facility, Schedule, OpenTime

# Other Imports
9
10
11
from rest_framework import serializers

class CategorySerializer(serializers.ModelSerializer):
12
13
    """
    """
14
15
    class Meta:
        model = Category
16
        fields = '__all__'
17
18

class OpenTimeSerializer(serializers.ModelSerializer):
19
20
    """
    """
21
22
    class Meta:
        model = OpenTime
23
        fields = '__all__'
24
25

class ScheduleSerializer(serializers.ModelSerializer):
26
27
    """
    """
Nicholas Anderson's avatar
Nicholas Anderson committed
28
    open_times = OpenTimeSerializer(many=True, read_only=True)
29

30
31
    class Meta:
        model = Schedule
David Haynes's avatar
David Haynes committed
32
33
        fields = ('id', 'open_times', 'modified', 'name', 'valid_start',
                  'valid_end')
34

35
class FacilitySerializer(serializers.HyperlinkedModelSerializer):
36
37
    """
    """
38
39
40
    category = CategorySerializer(many=False, read_only=True)
    main_schedule = ScheduleSerializer(many=False, read_only=True)
    special_schedules = ScheduleSerializer(many=True, read_only=True)
41
42
43

    class Meta:
        model = Facility
44
        fields = ('id', 'category', 'main_schedule', 'special_schedules',
David Haynes's avatar
David Haynes committed
45
                  'modified', 'name')