dsite/recipe/views.py
2021-08-24 18:09:00 +08:00

38 lines
1.3 KiB
Python

from django.shortcuts import render
# Create your views here.
import django.views.generic
from django.http import JsonResponse
from django.urls import reverse
from rest_framework import authentication, permissions, status, viewsets
import rest_framework.generics
from rest_framework.response import Response
from rest_framework.views import APIView
import recipe.models
import recipe.serializers
class RecipeAPI(rest_framework.generics.RetrieveUpdateAPIView,
rest_framework.generics.ListAPIView):
authentication_classes = (authentication.TokenAuthentication,
authentication.SessionAuthentication,
authentication.BasicAuthentication)
permission_classes = (permissions.IsAuthenticated,)
queryset = recipe.models.Recipe.objects.all()
serializer_class = recipe.serializers.RecipeSerializer
class RecipeListAPI(rest_framework.generics.ListAPIView,
rest_framework.generics.CreateAPIView):
authentication_classes = (authentication.TokenAuthentication,
authentication.SessionAuthentication,
authentication.BasicAuthentication)
permission_classes = (permissions.IsAuthenticated,)
queryset = recipe.models.Recipe.objects.all()
serializer_class = recipe.serializers.RecipeSerializer