Python 如何在django中通过多级反向外键获取相关对象查询集?

Python 如何在django中通过多级反向外键获取相关对象查询集?,python,django,django-models,foreign-keys,django-queryset,Python,Django,Django Models,Foreign Keys,Django Queryset,我有一个这样的模型: class Publisher(models.Model): ... class Author(models.Model): publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE) class Article(models.Model): author= models.ForeignKey(Author, on_delete=models.CASCADE) 现在,我正

我有一个这样的模型:

class Publisher(models.Model):
    ...

class Author(models.Model):
    publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)

class Article(models.Model):
    author= models.ForeignKey(Author, on_delete=models.CASCADE)
现在,我正在尝试从给定的出版商“pub”获取所有文章。 我试着做了以下几点:

pub.article_set()

pub.authot_set().article_set()

以及其他失败的可能性。那么,如何检索给定发布者的所有文章的查询集,而不必多次访问数据库呢?最有效的方法是什么


提前谢谢

减少数据库查询数量的最有效方法是对文章的查询集进行筛选

# pub is the instance of Publisher
articles = Article.objects.filter(author__publisher=pub)