Activate django-rest-framework and expose user model

This commit is contained in:
Tanner Collin 2018-09-12 01:45:03 -06:00
parent f081c38209
commit 48431a4d84
4 changed files with 24 additions and 3 deletions

View File

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

View File

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

View File

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

View File

@ -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'))
]