Add activity models in API

This commit is contained in:
Yohann D'ANELLO 2020-02-06 23:49:33 +01:00
parent 8e2b0688b5
commit 5de93066db
2 changed files with 48 additions and 4 deletions

View File

@ -0,0 +1,38 @@
# -*- 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):
class Meta:
model = ActivityType
fields = '__all__'
class ActivityTypeViewSet(viewsets.ModelViewSet):
queryset = ActivityType.objects.all()
serializer_class = ActivityTypeSerializer
class ActivitySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Activity
fields = '__all__'
class ActivityViewSet(viewsets.ModelViewSet):
queryset = Activity.objects.all()
serializer_class = ActivitySerializer
class GuestSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Guest
fields = '__all__'
class GuestViewSet(viewsets.ModelViewSet):
queryset = Guest.objects.all()
serializer_class = GuestSerializer

View File

@ -6,6 +6,7 @@ from django.conf.urls import url, include
from django.contrib.auth.models import User from django.contrib.auth.models import User
from rest_framework import routers, serializers, viewsets from rest_framework import routers, serializers, viewsets
from member.serializers import ProfileViewSet, ClubViewSet, RoleViewSet, MembershipViewSet from member.serializers import ProfileViewSet, ClubViewSet, RoleViewSet, MembershipViewSet
from activity.serializers import ActivityTypeViewSet, ActivityViewSet, GuestViewSet
class UserSerializer(serializers.HyperlinkedModelSerializer): class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
@ -19,10 +20,15 @@ class UserViewSet(viewsets.ModelViewSet):
# Routers provide an easy way of automatically determining the URL conf. # Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter() router = routers.DefaultRouter()
router.register(r'users', UserViewSet) router.register(r'users', UserViewSet)
router.register(r'profiles', ProfileViewSet)
router.register(r'clubs', ClubViewSet) router.register(r'members/profiles', ProfileViewSet)
router.register(r'roles', RoleViewSet) router.register(r'members/clubs', ClubViewSet)
router.register(r'memberships', MembershipViewSet) router.register(r'members/roles', RoleViewSet)
router.register(r'members/memberships', MembershipViewSet)
router.register(r'activity/activity_types', ActivityTypeViewSet)
router.register(r'activity/activities', ActivityViewSet)
router.register(r'activity/guests', GuestViewSet)
# Wire up our API using automatic URL routing. # Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API. # Additionally, we include login URLs for the browsable API.