'Is it possible to get all authors by single query in django

class Author(models.Model):
    name = models.CharField(max_length=50)

class Chapter(models.Model):
    book = models.ForeignKey(Album, on_delete=models.CASCADE)
    author = models.ManyToManyField("Author")

class Book(models.Model):
    author = models.ManyToManyField("Author")

I am trying to show all related authors when I visit one author detail. To do that currently I do this to achieve this:

authors = []
for chapter in Author.objects.get(id=id).chapter_set.all():
    authors.append(chapter.artists.all())

Is there any other way to do this by djangoORM



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source