mirror of https://gitlab.crans.org/bde/nk20
Add activity models in API
This commit is contained in:
parent
8e2b0688b5
commit
5de93066db
|
@ -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
|
|
@ -6,6 +6,7 @@ from django.conf.urls import url, include
|
|||
from django.contrib.auth.models import User
|
||||
from rest_framework import routers, serializers, viewsets
|
||||
from member.serializers import ProfileViewSet, ClubViewSet, RoleViewSet, MembershipViewSet
|
||||
from activity.serializers import ActivityTypeViewSet, ActivityViewSet, GuestViewSet
|
||||
|
||||
class UserSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
|
@ -19,10 +20,15 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
# Routers provide an easy way of automatically determining the URL conf.
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'users', UserViewSet)
|
||||
router.register(r'profiles', ProfileViewSet)
|
||||
router.register(r'clubs', ClubViewSet)
|
||||
router.register(r'roles', RoleViewSet)
|
||||
router.register(r'memberships', MembershipViewSet)
|
||||
|
||||
router.register(r'members/profiles', ProfileViewSet)
|
||||
router.register(r'members/clubs', ClubViewSet)
|
||||
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.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
|
|
Loading…
Reference in New Issue