Created
December 1, 2010 21:38
-
-
Save stopthink/724273 to your computer and use it in GitHub Desktop.
Combine multiple querysets from different models and sort by shared column (which can be fed into paginator)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from itertools import chain | |
| from operator import attrgetter | |
| collection = Collection.objects.get(pk=id) | |
| document_list = collection.documents.all() | |
| task_list = collection.tasks.all() | |
| item_list = sorted( | |
| chain(document_list, task_list), | |
| key=attrgetter('created'), | |
| reverse=True | |
| ) | |
| paginator = Paginator(item_list, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment