File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828 SpectacularSwaggerView .as_view (url_name = 'api-schema' ),
2929 name = 'api-docs' ,
3030 ),
31- path ('api/user/' , include ('user.urls' ))
31+ path ('api/user/' , include ('user.urls' )),
32+ path ('api/recipe/' , include ('recipe.urls' )),
3233]
Original file line number Diff line number Diff line change 1+ """
2+ URLs mapping for the recipe app
3+ """
4+ from django .urls import (
5+ path ,
6+ include ,
7+ )
8+
9+ from rest_framework .routers import DefaultRouter
10+
11+ from recipe import views
12+
13+
14+ router = DefaultRouter ()
15+ router .register ('recipes' , views .RecipeViewSet )
16+
17+ app_name = 'recipe'
18+
19+ urlpatterns = [
20+ path ('' , include (router .urls )),
21+ ]
Original file line number Diff line number Diff line change 1- from django .shortcuts import render # noqa
1+ """
2+ Views for the recipe APIs
3+ """
4+ from rest_framework import viewsets
5+ from rest_framework .authentication import TokenAuthentication
6+ from rest_framework .permissions import IsAuthenticated
7+
8+ from core .models import Recipe
9+ from recipe import serializers
10+
11+
12+ class RecipeViewSet (viewsets .ModelViewSet ):
13+ """View for manage recipe APIs"""
14+ serializer_class = serializers .RecipeSerializer
15+ queryset = Recipe .objects .all ()
16+ authentication_classes = [TokenAuthentication ]
17+ permission_classes = [IsAuthenticated ]
18+
19+ def get_queryset (self ):
20+ """Retrieve recipes for authenticated user"""
21+ return self .queryset .filter (user = self .request .user ).order_by ('-id' )
222
3- # Create your views here.
You can’t perform that action at this time.
0 commit comments