1 from django.db.models import Q
2 from catalogue.models import Book
5 def books_after(books, after, new_api):
7 return books.filter(slug__gt=after)
9 author, title, book_id = after.split(Book.SORT_KEY_SEP)
11 return Book.objects.none()
12 return books.filter(Q(sort_key_author__gt=author)
13 | (Q(sort_key_author=author) & Q(sort_key__gt=title))
14 | (Q(sort_key_author=author) & Q(sort_key=title) & Q(id__gt=int(book_id))))
17 def order_books(books, new_api):
19 return books.order_by('sort_key_author', 'sort_key', 'id')
21 return books.order_by('slug')