From f62e1498fd3f4f6c2e473390aadf18408fc9f360 Mon Sep 17 00:00:00 2001 From: Tyrel Souza <923113+tyrelsouza@users.noreply.github.com> Date: Sun, 15 Sep 2019 20:47:04 -0400 Subject: [PATCH] more serializers for users, i need one for user next --- logbook/flight/api.py | 3 ++- logbook/flight/serializers.py | 14 ++++++++++++++ logbook/flight/views.py | 20 +++++++++++++++++++- logbook/logbook/settings.py | 4 ++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/logbook/flight/api.py b/logbook/flight/api.py index 183cef4..eeee54e 100644 --- a/logbook/flight/api.py +++ b/logbook/flight/api.py @@ -6,7 +6,8 @@ router = routers.DefaultRouter() router.register(r"flights", views.FlightViewSet) router.register(r"planes", views.PlaneViewSet) router.register(r"airports", views.AirportViewSet) - +router.register(r"users", views.UserViewSet) +router.register(r"groups", views.GroupViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API. urlpatterns = [ diff --git a/logbook/flight/serializers.py b/logbook/flight/serializers.py index 2807459..d7b68a9 100644 --- a/logbook/flight/serializers.py +++ b/logbook/flight/serializers.py @@ -2,6 +2,20 @@ from django.contrib.auth.models import User, Group from rest_framework import serializers from flight.models import Flight, Plane, Airport +from django.contrib.auth.models import User, Group + + +class UserSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = User + fields = ["url", "username", "email", "groups"] + + +class GroupSerializer(serializers.HyperlinkedModelSerializer): + class Meta: + model = Group + fields = ["url", "name"] + class PlaneSerializer(serializers.HyperlinkedModelSerializer): class Meta: diff --git a/logbook/flight/views.py b/logbook/flight/views.py index 00ab22e..4665109 100644 --- a/logbook/flight/views.py +++ b/logbook/flight/views.py @@ -1,6 +1,24 @@ from rest_framework import viewsets -from flight.serializers import PlaneSerializer, AirportSerializer, FlightSerializer +from flight.serializers import ( + PlaneSerializer, + AirportSerializer, + FlightSerializer, + UserSerializer, + GroupSerializer, +) + from flight.models import Flight, Plane, Airport +from django.contrib.auth.models import User, Group + + +class UserViewSet(viewsets.ModelViewSet): + queryset = User.objects.all().order_by("-date_joined") + serializer_class = UserSerializer + + +class GroupViewSet(viewsets.ModelViewSet): + queryset = Group.objects.all() + serializer_class = GroupSerializer class PlaneViewSet(viewsets.ModelViewSet): diff --git a/logbook/logbook/settings.py b/logbook/logbook/settings.py index 3810858..7bd415e 100644 --- a/logbook/logbook/settings.py +++ b/logbook/logbook/settings.py @@ -119,6 +119,10 @@ CORS_ORIGIN_WHITELIST = ( "http://127.0.0.1:8000", "http://127.0.0.1:8001", "http://127.0.0.1:8081", + "http://localhost:8080", + "http://localhost:8000", + "http://localhost:8001", + "http://localhost:8081", ) REST_FRAMEWORK = {