From 48431a4d84af994331d749d16b390087f2f754b0 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 12 Sep 2018 01:45:03 -0600 Subject: [PATCH] Activate django-rest-framework and expose user model --- authserver/authserver/api/serializers.py | 7 +++++++ authserver/authserver/api/views.py | 8 ++++++-- authserver/authserver/settings.py | 1 + authserver/authserver/urls.py | 11 ++++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 authserver/authserver/api/serializers.py diff --git a/authserver/authserver/api/serializers.py b/authserver/authserver/api/serializers.py new file mode 100644 index 0000000..42c5093 --- /dev/null +++ b/authserver/authserver/api/serializers.py @@ -0,0 +1,7 @@ +from django.contrib.auth.models import User +from rest_framework import serializers + +class UserSerializer(serializers.ModelSerializer): + class Meta: + model = User + fields = ('username', 'email') diff --git a/authserver/authserver/api/views.py b/authserver/authserver/api/views.py index 91ea44a..560119a 100644 --- a/authserver/authserver/api/views.py +++ b/authserver/authserver/api/views.py @@ -1,3 +1,7 @@ -from django.shortcuts import render +from django.contrib.auth.models import User +from rest_framework import viewsets +from authserver.api.serializers import UserSerializer -# Create your views here. +class UserViewSet(viewsets.ModelViewSet): + queryset = User.objects.all().order_by('-date_joined') + serializer_class = UserSerializer diff --git a/authserver/authserver/settings.py b/authserver/authserver/settings.py index fcf4773..760520e 100644 --- a/authserver/authserver/settings.py +++ b/authserver/authserver/settings.py @@ -37,6 +37,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework', ] MIDDLEWARE = [ diff --git a/authserver/authserver/urls.py b/authserver/authserver/urls.py index b58c5d7..42c1d01 100644 --- a/authserver/authserver/urls.py +++ b/authserver/authserver/urls.py @@ -16,6 +16,15 @@ Including another URLconf from django.contrib import admin from django.urls import path +from django.conf.urls import url, include +from rest_framework import routers +from authserver.api import views + +router = routers.DefaultRouter() +router.register(r'user', views.UserViewSet, 'user') + urlpatterns = [ - path('admin/', admin.site.urls), + url(r'^', include(router.urls)), + url(r'^admin/', admin.site.urls), + url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) ]