如果 class 的相关集包含任意项,我如何获取它的所有条目?

How do I get all entries of a class if it's related set contains an arbitrary item?

class Book(models.Model):
    ...

class Page(models.Model):
    book = models.ForeignKey(Book)
    note = models.ForeignKey(Note)


class Note(models.Model):
    name = models.CharField()

从上面的例子,如何获取包含任意Note的所有Books实例?

my_note = Note.objects.get(name="Arbitrary")

pages_with_my_note = Page.objects.filter(note=my_note)

books_with_my_note = Book.objects.filter( ??? )

我在努力

pages_with_my_note.values_list("book").distinct() 但我得到:

TypeError: distinct_sql() missing 1 required positional argument: 'params'

简单地说,

books_with_my_note = Book.objects.filter(<b>page__note__name='Arbitrary'</b>).distinct()

参考: