The basic concept of context
in Django are well explained here and here, as well as Django doc. But I don't understand the following code that works in the Mozilla Django tutorial:
class BookListView(generic.ListView):
model = Book
def get_context_data(self, **kwargs):
context = super(BookListView, self).get_context_data(**kwargs)
context['author_books'] = Book.objects.filter(author=self.kwargs['pk'])
return context
Why is it necessary to define context
twice? Is it the same as:
author_books = # 'author_books' defined
book_list = # 'book_list' defined
context ={
'author_books': author_books,
'book_list': book_list,
}
Testing in Django shell didn't work for me as I'm still struggling with how to extract data from foreign-key items.