1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-30 04:13:01 +00:00

Add member models in API

This commit is contained in:
Yohann D'ANELLO 2020-02-06 23:43:56 +01:00
parent f4a665cb7f
commit edc428a05e
2 changed files with 52 additions and 3 deletions

View File

@ -5,14 +5,13 @@
from django.conf.urls import url, include 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
# Serializers define the API representation.
class UserSerializer(serializers.HyperlinkedModelSerializer): class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = User model = User
fields = ['url', 'username', 'email', 'is_staff'] fields = ['url', 'username', 'first_name', 'last_name', 'email', 'is_staff']
# ViewSets define the view behavior.
class UserViewSet(viewsets.ModelViewSet): class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all() queryset = User.objects.all()
serializer_class = UserSerializer serializer_class = UserSerializer
@ -20,6 +19,10 @@ 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'roles', RoleViewSet)
router.register(r'memberships', MembershipViewSet)
# 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.

View File

@ -0,0 +1,46 @@
from .models import Profile, Club, Role, Membership
from rest_framework import serializers, viewsets
class ProfileSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Profile
fields = '__all__'
class ProfileViewSet(viewsets.ModelViewSet):
queryset = Profile.objects.all()
serializer_class = ProfileSerializer
class ClubSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Club
fields = '__all__'
class ClubViewSet(viewsets.ModelViewSet):
queryset = Club.objects.all()
serializer_class = ClubSerializer
class RoleSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Role
fields = '__all__'
class RoleViewSet(viewsets.ModelViewSet):
queryset = Role.objects.all()
serializer_class = RoleSerializer
class MembershipSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Membership
fields = '__all__'
class MembershipViewSet(viewsets.ModelViewSet):
queryset = Membership.objects.all()
serializer_class = MembershipSerializer