SingleObjectMixin with ListView - querysets

You’re on the right track. Let’s break this down:

self.object is a reference to a Publisher.
self.object.book_set is a reference to a Manager.

  • What is it a Manager for?
    • It’s for all the books that are related to the Publisher.
      Therefore - self.object.book_set.all() is the queryset returning all books related to the Publisher.
      Functionally, it’s no different than Book.objects.filter(publisher=publisher_id)

The get method of ListView has the line:
self.object_list = self.get_queryset()

See get_template_names

See the Python topic “Method Resolution Order” among others. (A search will find many blogs explaining this topic.)

Also, two resources I’ve found extremely useful for understanding the generic CBVs are:

1 Like