cookbook/recipes/views.py

22 lines
636 B
Python
Raw Normal View History

2019-10-28 16:50:13 +01:00
from django.views import generic
2019-11-08 16:46:41 +01:00
from .models import Recipe, IngredientUsage, Step
2019-10-28 16:50:13 +01:00
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)
2019-11-08 16:46:41 +01:00
context['steps'] = Step.objects.filter(recipe=self.object.pk).order_by('step')
2019-10-28 16:50:13 +01:00
return context