Set up serializer

This commit is contained in:
Tanner Collin 2021-03-20 16:01:10 -06:00
parent cf2a059d4e
commit 24386dbcec
4 changed files with 23 additions and 19 deletions

View File

@ -0,0 +1,7 @@
from django.contrib.auth.models import User, Group
from rest_framework import serializers
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ['username', 'email', 'groups']

View File

@ -1,3 +1,9 @@
from django.shortcuts import render from django.contrib.auth.models import User, Group
from rest_framework import viewsets
from rest_framework import permissions
from server.api import serializers
# Create your views here. class UserViewSet(viewsets.ModelViewSet):
queryset = User.objects.all().order_by('-date_joined')
serializer_class = serializers.UserSerializer
permission_classes = [permissions.IsAuthenticated]

View File

@ -37,6 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework',
] ]
MIDDLEWARE = [ MIDDLEWARE = [

View File

@ -1,21 +1,11 @@
"""server URL Configuration from django.urls import include, path
from rest_framework import routers
from .api import views
The `urlpatterns` list routes URLs to views. For more information please see: router = routers.DefaultRouter()
https://docs.djangoproject.com/en/3.1/topics/http/urls/ router.register(r'users', views.UserViewSet)
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
] ]