diff --git a/apps/api/urls.py b/apps/api/urls.py index 39d795ea..bc7a68c7 100644 --- a/apps/api/urls.py +++ b/apps/api/urls.py @@ -5,14 +5,13 @@ 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 -# Serializers define the API representation. class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: 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): queryset = User.objects.all() serializer_class = UserSerializer @@ -20,6 +19,10 @@ 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) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. diff --git a/apps/member/serializers.py b/apps/member/serializers.py new file mode 100644 index 00000000..f16f664d --- /dev/null +++ b/apps/member/serializers.py @@ -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 +