I'd like to group records in two categories:
- Items having three or more records
- Items having less than three items
How do I go about this? I'm looking at using annotate().
I'd like to group records in two categories:
How do I go about this? I'm looking at using annotate().
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)