- 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()
+ books_nav = SortedDict()
+ for tag in models.Tag.objects.filter(category='author'):
+ books_by_author[tag] = []
+ if books_nav.has_key(tag.sort_key[0]):
+ books_nav[tag.sort_key[0]].append(tag)
+ else:
+ books_nav[tag.sort_key[0]] = [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)