Skip to content

Commit 6383c61

Browse files
committed
Add new album endpoint in API documentation
Expanded the "Building an API - Part II" section in the documentation to include detailed steps for creating an endpoint for the album model. This includes modifications to the 'music.urls.py' file in order to add routing for the newly created AlbumViewSet.
1 parent f68788d commit 6383c61

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

docs/images/index.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,30 @@ Congratulations now you have your first api working.
313313
- ⏳ Time for rest and informal discussions.
314314

315315
## Building an API - Part II
316-
Ok, so now we are going to create the apis for the other 2 models album and song model.
317316

317+
318+
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.
319+
320+
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.
321+
```python
322+
from django.urls import path, include
323+
from rest_framework import routers
324+
325+
from . import views
326+
from .views import ArtistViewSet, AlbumViewSet
327+
328+
router = routers.DefaultRouter()
329+
router.register(r'artists', ArtistViewSet)
330+
router.register(r'albums', AlbumViewSet)
331+
332+
urlpatterns = [
333+
path('', include(router.urls)),
334+
# path('', views.index, name='index'),
335+
]
336+
337+
```
338+
1. We added a new import for the AlbumViewSet
339+
2. We added the routes for albums
318340
## Bonus content
319341

320342
### Serializers deep dive

first_api/music/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from rest_framework import routers
33

44
from . import views
5-
from .views import ArtistViewSet
5+
from .views import ArtistViewSet, AlbumViewSet
66

77
router = routers.DefaultRouter()
88
router.register(r'artists', ArtistViewSet)
9+
router.register(r'albums', AlbumViewSet)
910

1011
urlpatterns = [
1112
path('', include(router.urls)),

0 commit comments

Comments
 (0)