From 4bf949bf575fdbc49924e36044b3b21d90a53fb9 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:12:57 -0700 Subject: [PATCH 01/10] Fix typo --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index c9236ec..e7a59eb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -243,7 +243,7 @@ def index(_request): return HttpResponse("My first API!") ``` -So no you can use the command `task r` to start our django server, so you can access [http://127.0.0.1:8000/](http://127.0.0.1:8000/) to see it. +So now you can use the command `task r` to start our django server, so you can access [http://127.0.0.1:8000/](http://127.0.0.1:8000/) to see it. ![my_first_api.png](images/my_first_api.png) Until here we just looked at Django concepts. Now we will dive into Django Rest Framework(DRF) concepts. From 060dc121287204e7cf2887a5ec90083b3b544fd9 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:17:15 -0700 Subject: [PATCH 02/10] Fix sequence logic Now it says view first and really implements the view first in sequence. --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index e7a59eb..1783033 100644 --- a/docs/index.md +++ b/docs/index.md @@ -278,7 +278,7 @@ class ArtistSerializer(serializers.HyperlinkedModelSerializer): 2. Create hyperlinks for the relationships 4. We need to pass explicitly the fields from the Artist model that will be in the serializer at the `fields` in the Meta class. -With the serializer in place we need more 2 steps, the url mapping and the view. +With the serializer in place we need more 2 steps, the view and the url mapping. Let's do both in sequence, first the view. For the view we are going to use a [ModelViewSet](https://www.django-rest-framework.org/api-guide/viewsets/#modelviewset). Inside our file `music.views.py` we need to add this snipper. From 8eac47b0f4249dd47d71906233fb8de68c7105e7 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:17:56 -0700 Subject: [PATCH 03/10] Fix typo --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 1783033..fdda3db 100644 --- a/docs/index.md +++ b/docs/index.md @@ -280,7 +280,7 @@ class ArtistSerializer(serializers.HyperlinkedModelSerializer): With the serializer in place we need more 2 steps, the view and the url mapping. -Let's do both in sequence, first the view. For the view we are going to use a [ModelViewSet](https://www.django-rest-framework.org/api-guide/viewsets/#modelviewset). Inside our file `music.views.py` we need to add this snipper. +Let's do both in sequence, first the view. For the view we are going to use a [ModelViewSet](https://www.django-rest-framework.org/api-guide/viewsets/#modelviewset). Inside our file `music.views.py` we need to add this snippet. ```python # music/views.py From c403233ca7273cf58582e18e45791af011a7a300 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:19:46 -0700 Subject: [PATCH 04/10] Fix grammar --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index fdda3db..1ce5ff3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -290,7 +290,7 @@ class ArtistViewSet(viewsets.ModelViewSet): serializer_class = ArtistSerializer ``` -1. Here we create a ViewSet class that will be responsible to create our CRUD(+ list) views. It inherits from `ModelViewSet`. +1. Here we create a ViewSet class that will be responsible for creating our CRUD(+ list) views. It inherits from `ModelViewSet`. 2. `queryset` parameter tells DRF what do list, this will be shared across all the views 3. `serializer_class` is self-explanatory From 568d02aceeaecec9bf67baa8cadaf00691e18839 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:26:33 -0700 Subject: [PATCH 05/10] Fix typo --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 1ce5ff3..526fc93 100644 --- a/docs/index.md +++ b/docs/index.md @@ -92,7 +92,7 @@ cd building-your-first-api-with-django-and-django-rest-framework uv venv source .venv/bin/activate # if you are on Windows use: .venv\Scripts\activate uv sync -task run # to see the application running +task r # to see the application running ``` You might be able to see the application running o [127.0.0.1:8000](http://127.0.0.1:8000/). From 44f3c01a6aad0b337a2df5d8038baca58606ebcd Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:28:46 -0700 Subject: [PATCH 06/10] Fix grammar --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 526fc93..b8c356b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -352,7 +352,7 @@ Congratulations now you have your first api working. Now that you've explored some of the shortcuts provided by DRF, let's delve into creating an endpoint for the album model using a plain Serializer, without relying heavily on shortcuts. -Let's start by the urls part. We gonna need to add the new route to our `music.urls.py`. Now it should look like this. +Let's start by the urls part. We're going to need to add the new route to our `music.urls.py`. Now it should look like this. ```python from django.urls import path, include From a9ac2ccfa51e8b2412da7f1886414e531ddf67f7 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:36:51 -0700 Subject: [PATCH 07/10] Fix missing word --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index b8c356b..1bdedd4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -441,7 +441,7 @@ First the `list` method. return Response(serializer.data) ``` -1. Here we just need to serialize the queryset and return it as a +1. Here we just need to serialize the queryset and return it as a `Response` 2. Don't forget to import the `from rest_framework.response import Response` The following action will be `create` From f7197115d5f64272184b46bbcb97cb6b339264bf Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 02:47:59 -0700 Subject: [PATCH 08/10] Fix typo and add pauses --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 1bdedd4..8bf13e1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -538,7 +538,7 @@ The first is `create` return Album.objects.create(artist=artist, **validated_data) ``` -1. Where we create the album but since the album has artist as a nested model we need to create it here before try to save the album itself. +1. We create the album, but since the album has artist as a nested model, we need to create it here before try to save the album itself. 2. Don't forget to import the `Album` model here with `from music.models import Album` and the `update` method From deaaad743fd4e4e868a0bcdaba11d02800ace542 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 03:03:46 -0700 Subject: [PATCH 09/10] Add instructions for missing imports --- docs/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/index.md b/docs/index.md index 8bf13e1..68b602d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -386,6 +386,8 @@ class AlbumViewSet(viewsets.ViewSet): 1. Here we create a class `AlbumViewSet` inheriting from `views.ViewSet`, pay attention, this is nos a model view set. 2. Set the `queryset` 3. Set `serializer_class`, we are going to talk about this `AlbumSerializer` later +4. For now, just import the `AlbumSerializer` with `from music.serializers import AlbumSerializer` +5. Don't forget to import the Album model here with `from music.models import Album` After this still in the same view we are going through what DRF call actions. Instead of have methods in the view set for get, post, delete... It has functions based on actions. The actions are the ones below: From 22ed37d61cefd505d3a697eeba331fde51026e79 Mon Sep 17 00:00:00 2001 From: Fang Yi Liu Date: Sun, 29 Sep 2024 03:08:15 -0700 Subject: [PATCH 10/10] Add missing import instruction --- docs/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 68b602d..987b5e5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -594,9 +594,10 @@ urlpatterns = [ ] ``` -After this we are going to create the `SongViewSet` in our `music.views` file using a `ModelViewSet` like in the snippet below. Also update Don't forget to add the import for the `SongSerializer` in your imports +After this we are going to create the `SongViewSet` in our `music.views` file using a `ModelViewSet` like in the snippet below. Also update Don't forget to add the import for `Song` and `SongSerializer` in your imports ```python +from music.models import Artist, Album, Song from music.serializers import ArtistSerializer, AlbumSerializer, SongSerializer class SongViewSet(viewsets.ModelViewSet):