34 lines
942 B
Python
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']
|
|
)
|