nk20/apps/activity/serializers.py

66 lines
2.1 KiB
Python
Raw Normal View History

2020-02-06 22:49:33 +00:00
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from .models import ActivityType, Activity, Guest
from rest_framework import serializers, viewsets
class ActivityTypeSerializer(serializers.HyperlinkedModelSerializer):
2020-02-06 23:29:04 +00:00
"""
REST API Serializer for Activity types.
The djangorestframework plugin will analyse the model `ActivityType` and parse all fields in the API.
"""
2020-02-06 22:49:33 +00:00
class Meta:
model = ActivityType
fields = '__all__'
class ActivityTypeViewSet(viewsets.ModelViewSet):
2020-02-06 23:29:04 +00:00
"""
REST API View set.
The djangorestframework plugin will get all `ActivityType` objects, serialize it to JSON with the given serializer,
then render it on /api/activity/type/
"""
2020-02-06 22:49:33 +00:00
queryset = ActivityType.objects.all()
serializer_class = ActivityTypeSerializer
class ActivitySerializer(serializers.HyperlinkedModelSerializer):
2020-02-06 23:29:04 +00:00
"""
REST API Serializer for Activities.
The djangorestframework plugin will analyse the model `Activity` and parse all fields in the API.
"""
2020-02-06 22:49:33 +00:00
class Meta:
model = Activity
fields = '__all__'
class ActivityViewSet(viewsets.ModelViewSet):
2020-02-06 23:29:04 +00:00
"""
REST API View set.
The djangorestframework plugin will get all `Activity` objects, serialize it to JSON with the given serializer,
then render it on /api/activity/activity/
"""
2020-02-06 22:49:33 +00:00
queryset = Activity.objects.all()
serializer_class = ActivitySerializer
class GuestSerializer(serializers.HyperlinkedModelSerializer):
2020-02-06 23:29:04 +00:00
"""
REST API Serializer for Guests.
The djangorestframework plugin will analyse the model `Guest` and parse all fields in the API.
"""
2020-02-06 22:49:33 +00:00
class Meta:
model = Guest
fields = '__all__'
class GuestViewSet(viewsets.ModelViewSet):
2020-02-06 23:29:04 +00:00
"""
REST API View set.
The djangorestframework plugin will get all `Guest` objects, serialize it to JSON with the given serializer,
then render it on /api/activity/guest/
"""
2020-02-06 22:49:33 +00:00
queryset = Guest.objects.all()
serializer_class = GuestSerializer