- books_by_first_letter = SortedDict()
- for book in books:
- books_by_first_letter.setdefault(book.title[0], []).append(book)
+ books_by_parent = {}
+ for book in models.Book.objects.all().order_by('parent_number'):
+ books_by_parent.setdefault(book.parent, []).append(book)
+
+ orphans = []
+ books_by_author = SortedDict()
+ for tag in models.Tag.objects.filter(category='author'):
+ books_by_author[tag] = []
+
+ for book in books_by_parent[None]:
+ authors = list(book.tags.filter(category='author'))
+ if authors:
+ for author in authors:
+ books_by_author[author].append(book)
+ else:
+ orphans.append(book)