This commit is contained in:
Arthur
2019-04-20 15:15:32 +02:00
parent d8ac11921f
commit 2e7553b70c
46 changed files with 1871 additions and 721 deletions

33
recipe_book/views.py Normal file
View 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']
)