20 lines
543 B
Python
20 lines
543 B
Python
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
|