I have the following models:
class Book(models.Model):
name = models.CharField()
authors = models.ManyToManyField('Author', blank=True, verbose_name=_('authors'))
class Author(models.Model):
name = models.CharField()
def my_books(self) -> List[Book]:
return Book.objects.filter(authors__exact=self.id).all()
I am displaying author and related books via DetailView:
class AuthorDetailView(generic.DetailView):
model = Author
In the template, I am accessing books of a given author via author.my_books() method - but this pulls ALL ROWS from the database.
I want to paginate the book rows.
How do I achieve that?
Update: According to this answer, I need to subclass ListView rather than DetailView, and override get_queryset() to fetch the books. Is there any way to do that in DetailView?