Skip to content

Commit

Permalink
adds in class demo 31 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JB-Tellez committed Feb 19, 2024
1 parent 3b0be3b commit fad7954
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 33 deletions.
4 changes: 0 additions & 4 deletions class-31/demo/things-api/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
# .dockerignore
.venv
.git
.gitignore
1 change: 0 additions & 1 deletion class-31/demo/things-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Pull base image
FROM python:3.11.5-slim-bullseye

# Set environment variables
Expand Down
Binary file modified class-31/demo/things-api/db.sqlite3
Binary file not shown.
14 changes: 7 additions & 7 deletions class-31/demo/things-api/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion class-31/demo/things-api/things/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions class-31/demo/things-api/things/models.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -11,3 +10,6 @@ class Thing(models.Model):

def __str__(self):
return self.name



11 changes: 7 additions & 4 deletions class-31/demo/things-api/things/serializers.py
Original file line number Diff line number Diff line change
@@ -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




3 changes: 3 additions & 0 deletions class-31/demo/things-api/things/tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions class-31/demo/things-api/things/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .views import ThingList, ThingDetail

urlpatterns = [
path("", ThingList.as_view(), name="thing_list"),
path("<int:pk>/", ThingDetail.as_view(), name="thing_detail"),
path("", ThingList.as_view(), name="thing_list"),
path("<int:pk>/", ThingDetail.as_view(), name="thing_detail"),
]
14 changes: 6 additions & 8 deletions class-31/demo/things-api/things/views.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions class-31/demo/things-api/things_api_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]


Expand All @@ -43,8 +43,7 @@
# 3rd party
'rest_framework',

# in house
'things'
'things',
]

MIDDLEWARE = [
Expand Down
1 change: 1 addition & 0 deletions class-31/demo/things-api/things_api_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

0 comments on commit fad7954

Please sign in to comment.