cookbook/recipes/views.py

22 lines
636 B
Python

from django.views import generic
from .models import Recipe, IngredientUsage, Step
class IndexView(generic.ListView):
template_name = 'recipes/index.html'
def get_queryset(self):
return Recipe.objects.order_by('name')
class DetailView(generic.DetailView):
model = Recipe
template_name = 'recipes/detail.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['ingredient_list'] = IngredientUsage.objects.filter(recipe=self.object.pk)
context['steps'] = Step.objects.filter(recipe=self.object.pk).order_by('step')
return context