Basic setup

This commit is contained in:
Tanner Collin 2022-04-25 21:50:02 +00:00
parent 7be3e6a39d
commit 6c0054e72d
4 changed files with 37 additions and 23 deletions

View File

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

View File

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

View File

@ -25,7 +25,9 @@ SECRET_KEY = 'django-insecure-au(y+z)$-iy#(obif&ilg*_pn0j_+0u=q*p7h(3c-ii-euncwx
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = [
'api.soak.stctech.ca',
]
# Application definition # Application definition
@ -37,6 +39,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 = [
@ -75,12 +78,15 @@ WSGI_APPLICATION = 'apiserver.wsgi.application'
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.postgresql',
'NAME': BASE_DIR / 'db.sqlite3', 'NAME': 'django',
'USER': 'django',
'PASSWORD': 'django',
'HOST': '127.0.0.1',
'PORT': '5432',
} }
} }
# Password validation # Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators

View File

@ -1,21 +1,13 @@
"""apiserver URL Configuration from django.urls import include, path
from rest_framework import routers
from apiserver.api import views
The `urlpatterns` list routes URLs to views. For more information please see: router = routers.DefaultRouter()
https://docs.djangoproject.com/en/4.0/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
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
] ]