Files
django-cookAssistant/recipe_book/views.py
Arthur 2e7553b70c init
2019-04-20 15:15:32 +02:00

34 lines
942 B
Python

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']
)