Created
August 2, 2016 14:10
-
-
Save kezabelle/f9bd118088a088162873965dad3a4eca to your computer and use it in GitHub Desktop.
Get the queryset with the most results, for blackcross in #django IRC
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
querysets = ( | |
Page.objects.filter(...), | |
Something.objects.exclude(...), | |
Etc.objects.filter(...), | |
) | |
results = {qs.count(): (index, qs) for index, qs in enumerate(querysets)} | |
best = max(results) | |
worst = min(results) | |
if best > 0: | |
best_counts = results[best][1] | |
if worst > 0: | |
worst_counts = results[worst][1] | |
# note you can also figure out what index gave you the best results by looking at [0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment