Skip to content

Instantly share code, notes, and snippets.

@grokcode
Created November 28, 2012 03:38
Show Gist options
  • Save grokcode/4158876 to your computer and use it in GitHub Desktop.
Save grokcode/4158876 to your computer and use it in GitHub Desktop.
year_ago = date.today() - timedelta(days=365)
q_new_books = Q(orig_pub_date=None) | Q(orig_pub_date__gt=year_ago)
q_multiple_books = Q(book__count__gt=1)
qs = Works.objects.all()
len(qs.annotate(Count('book')).filter(q_new_books)) # 14
len(qs.annotate(Count('book')).filter(q_multiple_books)) # 72
len(qs.annotate(Count('book')).filter(q_new_books | q_multiple_books)) # 8 WTF?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment