cookbook/recipes/views.py

21 lines
543 B
Python
Raw Normal View History

2019-10-28 16:50:13 +01:00
from django.views import generic
from .models import Recipe, IngredientUsage
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)
return context