add a REST API for participants

This commit is contained in:
Dustin J. Mitchell 2020-10-15 17:34:21 +00:00 коммит произвёл Dustin J. Mitchell
Родитель e053250a5f
Коммит 2b53843c91
5 изменённых файлов: 33 добавлений и 1 удалений

Просмотреть файл

@ -9,6 +9,7 @@ Stuff to do!
* pairing
* show existing pairings
* "unpair" button
* check in model that pair.mentor.role == MENTOR etc.
* provide data to a react app, allow filtering, etc.
* hardening

Просмотреть файл

@ -0,0 +1,15 @@
from rest_framework import serializers, viewsets, permissions
from .models import Participant
class ParticipantSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Participant
fields = '__all__'
# ViewSets define the view behavior.
class ParticipantViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = [permissions.IsAuthenticated]
queryset = Participant.objects.all()
serializer_class = ParticipantSerializer

6
mentoring/rest.py Normal file
Просмотреть файл

@ -0,0 +1,6 @@
from rest_framework import serializers, viewsets, routers
from .participants.rest import ParticipantViewSet
router = routers.DefaultRouter(trailing_slash=False)
router.register(r'participants', ParticipantViewSet)

Просмотреть файл

@ -25,7 +25,9 @@ SECRET_KEY = '54ld$bgd#&@os*u2^t)06b)8@-#m&2zhe_4k+*xs_k6f*n*o_a'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS = [
'mentoring.ngrok.io',
]
# Project-specific confit

Просмотреть файл

@ -1,9 +1,17 @@
from django.contrib import admin
from django.urls import include, path
from . import rest
urlpatterns = [
# the POST destination for enrollment via SurveyGizmo
path('enrollment/', include('mentoring.enrollment.urls')),
# TODO
path('pairing/', include('mentoring.pairing.urls')),
# the Django admin
path('admin/', admin.site.urls),
# the API
path('api/', include(rest.router.urls)),
# ..and anything else renders the frontend
path('', include('mentoring.frontend.urls')),
]