Count books by author/genre using intermediate tables.
def update_counters():
for author in Author.select():
- author.count = len(author.books)
+ author.count = AuthorBook.select(AuthorBook.q.author == author).count()
for ext in Extension.select():
ext.count = Book.select(Book.q.extension == ext.name).count()
for genre in Genre.select():
- genre.count = len(genre.books)
+ genre.count = BookGenre.select(BookGenre.q.genre == genre).count()
for language in Language.select():
language.count = Book.select(Book.q.language == language.name).count()