serializers.py 1 KB
Newer Older
1
2
3
4
5
6
from rest_framework import serializers
from website.models import Category, Facility, Schedule, OpenTime

class CategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = Category
7
        fields = '__all__'
8
9
10
11

class OpenTimeSerializer(serializers.ModelSerializer):
    class Meta:
        model = OpenTime
12
        fields = '__all__'
13
14

class ScheduleSerializer(serializers.ModelSerializer):
Nicholas Anderson's avatar
Nicholas Anderson committed
15
    open_times = OpenTimeSerializer(many=True, read_only=True)
16
17
    class Meta:
        model = Schedule
18
        fields = ( 'id', 'open_times', 'last_modified', 'name', 'valid_start', 'valid_end' )
19

20
21
22
23
class FacilitySerializer(serializers.HyperlinkedModelSerializer):
    category = CategorySerializer(many=False, read_only=True)
    main_schedule = ScheduleSerializer(many=False, read_only=True)
    special_schedules = ScheduleSerializer(many=True, read_only=True)
24
25
26

    class Meta:
        model = Facility
27
        fields = ( 'id', 'category', 'main_schedule', 'special_schedules', 'location', 'last_modified', 'name' )
28