more serializers for users, i need one for user next
This commit is contained in:
parent
f40d4ea281
commit
f62e1498fd
@ -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 = [
|
||||
|
@ -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:
|
||||
|
@ -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):
|
||||
|
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user