From fad7954fdd4f9d92af571635e9c6e739c90598be Mon Sep 17 00:00:00 2001 From: JB Tellez Date: Mon, 19 Feb 2024 12:06:14 -0800 Subject: [PATCH] adds in class demo 31 changes --- class-31/demo/things-api/.dockerignore | 4 ---- class-31/demo/things-api/Dockerfile | 1 - class-31/demo/things-api/db.sqlite3 | Bin 139264 -> 139264 bytes class-31/demo/things-api/docker-compose.yml | 14 +++++++------- .../things/migrations/0001_initial.py | 2 +- class-31/demo/things-api/things/models.py | 6 ++++-- .../demo/things-api/things/serializers.py | 11 +++++++---- class-31/demo/things-api/things/tests.py | 3 +++ class-31/demo/things-api/things/urls.py | 4 ++-- class-31/demo/things-api/things/views.py | 14 ++++++-------- .../things-api/things_api_project/settings.py | 7 +++---- .../things-api/things_api_project/urls.py | 1 + 12 files changed, 34 insertions(+), 33 deletions(-) diff --git a/class-31/demo/things-api/.dockerignore b/class-31/demo/things-api/.dockerignore index f32ebbe..e69de29 100644 --- a/class-31/demo/things-api/.dockerignore +++ b/class-31/demo/things-api/.dockerignore @@ -1,4 +0,0 @@ -# .dockerignore -.venv -.git -.gitignore diff --git a/class-31/demo/things-api/Dockerfile b/class-31/demo/things-api/Dockerfile index 88e391b..cb6e3a2 100644 --- a/class-31/demo/things-api/Dockerfile +++ b/class-31/demo/things-api/Dockerfile @@ -1,4 +1,3 @@ -# Pull base image FROM python:3.11.5-slim-bullseye # Set environment variables diff --git a/class-31/demo/things-api/db.sqlite3 b/class-31/demo/things-api/db.sqlite3 index 7d45e32060fae4d613b4ce6fbbb7f0ad3f5bc292..81f2230d758e52bfd094ff33e4301626f97d2687 100644 GIT binary patch delta 1449 zcmah{O>7%Q7~PHCx*L>Cf>c!{apQ(W`~*8Yv$H!pR*P6WPMshBCACeAkXf%c{*N6y zb{tn#QV=INfL7wrONEdShxR}t^*}ErPi*+_`hYF6{U znfHC~?b|yzvv+XjqcMK=4)_4v1o{1oo+x;J@3t!#R zRwK1UPhLw#cG~sJNJQ8xA}?fe)Tbens83=UlOXKd(qG=_uRfz*vmX~FzYKj8QIX)g z4X5WcKm3pze#jJjJG}euB!4RM-m2EkR}I=gWhG~{JKbs}XLi)Qls90J^vrs*=`$C* zsq$Pawq4c|0W({=QmtmPRIfE+Mxh^6H6 zqFC5m>BiE@dZ1hl=s`8rSk_jPk)?%bYGEaq&=Zlu=9-qNEqCTP1IH_&?L`?m0c5IS&s{^WX^wp6rkA{Q+DY=XCIb>+_L;k$VTcbA%Ni zaNq%B{R&+2^8yFX3p2c+!En1)Yq#FIHmT?HW`5G|xpw{f+b;XRh0rfSA4H-;;Jsgt z*dB4<5o7xSyy|vn!hdTT0=KvU5aU1$++kq|g5BtVi#t1`X+pfTrAPD~Pf_ofo<`lM zm|OO~xZhV|8N}#B1^Xq{M+t-~Wu^_EUtoNFDG7&*bHBoN$&He+V^qzsUS0R-p4`z6 viLcv2j{T5@9AZT}(LsJzA<7{5i)nbwfj_}xrukPe>~sjc9#(=|)IU&?K|-vojkkn8pZN+S(Lsk6mh-+SsOvvc+CZ z51#bUI^e;JDEM;_s_wxorI%MAvh)SeZo>GcbK3u zo}?-z7ANvbQYh4>j1l=L$rZ{Nx2XJ*JgZPjF}5X5;eFkIX2fPldMWiWLYal+UP=|i zK?5RxAE>o#>ezC8R2>ZwC+KibrP!fFF!^z`*e`~;AOg!1CQkLO40D7SLIV+SEL(D~ zu3lS{kIfO~9&}G%fcBg=6@>WkiG)oN|=pp9o2@x))RFE?+}*%AF{0;t4T6d-2vxeQvT)JKbDd2TF;)avb;do#V%Y^Sf+ ZT(5THfQbE91lxi!@xP2?KYOJae*l3x%E$l! diff --git a/class-31/demo/things-api/docker-compose.yml b/class-31/demo/things-api/docker-compose.yml index 2f4aaaf..0cb2279 100644 --- a/class-31/demo/things-api/docker-compose.yml +++ b/class-31/demo/things-api/docker-compose.yml @@ -1,8 +1,8 @@ services: - web: - build: . - ports: - - "8000:8000" - command: python manage.py runserver 0.0.0.0:8000 - volumes: - - .:/code + web: + build: . + ports: + - "8000:8000" + command: python manage.py runserver 0.0.0.0:8000 + volumes: + - .:/code diff --git a/class-31/demo/things-api/things/migrations/0001_initial.py b/class-31/demo/things-api/things/migrations/0001_initial.py index 7221ab2..5011a0d 100644 --- a/class-31/demo/things-api/things/migrations/0001_initial.py +++ b/class-31/demo/things-api/things/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.0.2 on 2024-02-17 16:54 +# Generated by Django 5.0.2 on 2024-02-19 17:56 import django.db.models.deletion from django.conf import settings diff --git a/class-31/demo/things-api/things/models.py b/class-31/demo/things-api/things/models.py index feae5be..6c298d1 100644 --- a/class-31/demo/things-api/things/models.py +++ b/class-31/demo/things-api/things/models.py @@ -1,6 +1,5 @@ -from django.contrib.auth import get_user_model from django.db import models - +from django.contrib.auth import get_user_model class Thing(models.Model): owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) @@ -11,3 +10,6 @@ class Thing(models.Model): def __str__(self): return self.name + + + diff --git a/class-31/demo/things-api/things/serializers.py b/class-31/demo/things-api/things/serializers.py index 0f6ea28..68ce8c2 100644 --- a/class-31/demo/things-api/things/serializers.py +++ b/class-31/demo/things-api/things/serializers.py @@ -1,8 +1,11 @@ from rest_framework import serializers from .models import Thing - class ThingSerializer(serializers.ModelSerializer): - class Meta: - fields = ("id", "owner", "name", "description", "created_at") - model = Thing + class Meta: + fields = ("id","owner","name","description","created_at") + model = Thing + + + + diff --git a/class-31/demo/things-api/things/tests.py b/class-31/demo/things-api/things/tests.py index d2170ef..315a131 100644 --- a/class-31/demo/things-api/things/tests.py +++ b/class-31/demo/things-api/things/tests.py @@ -1,3 +1,6 @@ +from django.test import TestCase + +# Create your tests here. from django.contrib.auth import get_user_model from django.urls import reverse from rest_framework import status diff --git a/class-31/demo/things-api/things/urls.py b/class-31/demo/things-api/things/urls.py index 28cd8e6..0941b29 100644 --- a/class-31/demo/things-api/things/urls.py +++ b/class-31/demo/things-api/things/urls.py @@ -2,6 +2,6 @@ from .views import ThingList, ThingDetail urlpatterns = [ - path("", ThingList.as_view(), name="thing_list"), - path("/", ThingDetail.as_view(), name="thing_detail"), + path("", ThingList.as_view(), name="thing_list"), + path("/", ThingDetail.as_view(), name="thing_detail"), ] diff --git a/class-31/demo/things-api/things/views.py b/class-31/demo/things-api/things/views.py index a7bd626..b29f092 100644 --- a/class-31/demo/things-api/things/views.py +++ b/class-31/demo/things-api/things/views.py @@ -1,18 +1,16 @@ -from rest_framework import generics -from .serializers import ThingSerializer +from rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView from .models import Thing +from .serializers import ThingSerializer - -class ThingList(generics.ListCreateAPIView): - +class ThingList(ListCreateAPIView): # Anything that inherits from ListAPI View is going to need 2 things. # What is the collection of things, aka the queryset - # Serializer_class queryset = Thing.objects.all() - serializer_class = ThingSerializer + #serializing + serializer_class = ThingSerializer # The ThingDetail needs the same things -class ThingDetail(generics.RetrieveUpdateDestroyAPIView): +class ThingDetail(RetrieveUpdateDestroyAPIView): queryset = Thing.objects.all() serializer_class = ThingSerializer diff --git a/class-31/demo/things-api/things_api_project/settings.py b/class-31/demo/things-api/things_api_project/settings.py index 5560b84..cff52e1 100644 --- a/class-31/demo/things-api/things_api_project/settings.py +++ b/class-31/demo/things-api/things_api_project/settings.py @@ -20,13 +20,13 @@ # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'django-insecure-y0hx8ys-r4d0qr9jw_a&^=*f%h2kkvs-avlav1%0lx1t1tqdn&' +SECRET_KEY = 'django-insecure-t3&@2q8p#qahrf(0c1ktj8lnr3apv-ko11&qafp6rq_-50@1u!' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [ - '0.0.0.0', + '0.0.0.0', ] @@ -43,8 +43,7 @@ # 3rd party 'rest_framework', - # in house - 'things' + 'things', ] MIDDLEWARE = [ diff --git a/class-31/demo/things-api/things_api_project/urls.py b/class-31/demo/things-api/things_api_project/urls.py index 819fa91..d19d268 100644 --- a/class-31/demo/things-api/things_api_project/urls.py +++ b/class-31/demo/things-api/things_api_project/urls.py @@ -20,4 +20,5 @@ urlpatterns = [ path('admin/', admin.site.urls), path("api/v1/things/", include("things.urls")), + path('api-auth/', include('rest_framework.urls')), # Adds login to the browsable API ]