[Fixed]-Newbie – understanding Django's class-based views dynamic filtering

1👍

Setting context['publisher'] = self.publisher in get_context_data means you can display the publisher’s details in the context. For example, you could display the publisher’s name above the list of book titles with:

<h2>Books published by {{ publisher.name }}</h2>

{% for book in book_list %}
    {{ book.title }}
{% endfor %}

0👍

You can access related objects as described here: What is `related_name` used for in Django? .

Try calling either publisher.books.all() or publisher.book_set.all():

{% for book in publiser.book_set.all %}
    {{ book.title }}
{% endfor %}
👤Udi

Leave a comment