init
This commit is contained in:
33
recipe_book/views.py
Normal file
33
recipe_book/views.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from recipe_book.serializers import (
|
||||
RecipeSerializer,
|
||||
IngredientSerializer,
|
||||
IngredientWithAmountSerializer,
|
||||
)
|
||||
from recipe_book.models import (
|
||||
Recipe,
|
||||
Ingredient,
|
||||
IngredientWithAmount,
|
||||
)
|
||||
|
||||
class RecipesViewSet(viewsets.ModelViewSet):
|
||||
queryset = Recipe.objects.all()
|
||||
serializer_class = RecipeSerializer
|
||||
|
||||
|
||||
class IngredientViewSet(viewsets.ModelViewSet):
|
||||
queryset = Ingredient.objects.all()
|
||||
serializer_class = IngredientSerializer
|
||||
|
||||
|
||||
class IngredientWAmountViewSet(viewsets.ModelViewSet):
|
||||
serializer_class = IngredientWithAmountSerializer
|
||||
lookup_field = 'ingredient'
|
||||
|
||||
def get_queryset(self):
|
||||
return IngredientWithAmount.objects.filter(
|
||||
recipe=self.kwargs['recipe_pk']
|
||||
)
|
||||
Reference in New Issue
Block a user