I'm trying to follow and learning about dynamic filtering in Django from the docs. https://docs.djangoproject.com/en/1.10/topics/class-based-views/generic-display/#dynamic-filtering I've just been following along step by step and copy/pasted the code from docs. But I don't understand the last bit about added the publisher into the context, meaning I can't figure out how to query that data in the template. The only thing I can get a "hold" of publisher.
Because in the PublisherDetail view publisher_detail.html
you would just do something straight forward like this, to list all the books from a publisher:
{% for book in book_list %}
{{ book.title }}
{% endfor %}
This is part that is tripping me up.
We can also add the publisher into the context at the same time, so we can use it in the template:
# ...
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(PublisherBookList, self).get_context_data(**kwargs)
# Add in the publisher
context['publisher'] = self.publisher
return context