views:

56

answers:

1

I'd like to group records in two categories:

  1. Items having three or more records
  2. Items having less than three items

How do I go about this? I'm looking at using annotate().

+2  A: 
q = Book.objects.annotate(num_authors=Count('authors'))
books_with_3_or_over_authors = q.filter(num_authors__gte=3)
books_with_less_than_3_authors = q.filter(num_authors__lt=3)
Lakshman Prasad
thanks...this is what I needed.
Stephen