more serializers for users, i need one for user next

This commit is contained in:
Tyrel Souza 2019-09-15 20:47:04 -04:00
parent f40d4ea281
commit f62e1498fd
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
4 changed files with 39 additions and 2 deletions

View File

@ -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 = [

View File

@ -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:

View File

@ -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):

View File

@ -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 = {