... wards. # Each publisher, each with a count of books as a "num_books" attribute. >>> from django.db.models import Count >>> pubs = Publisher . objects . annotate ( num_books = Count ( "book" )) >>> pubs <QuerySet [<Publisher: BaloneyPress>, <Publisher ... : SalamiPress>, ...]> >>> pubs [ 0 ] . num_books 73 # Each publisher, with a separate count of books with a rating above and below 5 >>> from django.db.m ... t ( "book" , filter = Q ( book__rating__gt = 5 )) >>> below_5 = Count ( "book" , filter = Q ( book__rating__lte = 5 )) >>> pubs = Publisher . objects . annotate ( below_5 = below_5 ) . annotate ( above_5 = above_5 ) >>> pubs [ 0 ] . above_5 23 >>> pu ... ... wards. # Each publisher, each with a count of books as a "num_books" attribute. >>> from django.db.models import Count >>> pubs = Publisher . objects . annotate ( num_books = Count ( "book" )) >>> pubs <QuerySet [<Publisher: BaloneyPress>, <Publisher ... : SalamiPress>, ...]> >>> pubs [ 0 ] . num_books 73 # Each publisher, with a separate count of books with a rating above and below 5 >>> from django.db.m ... t ( "book" , filter = Q ( book__rating__gt = 5 )) >>> below_5 = Count ( "book" , filter = Q ( book__rating__lte = 5 )) >>> pubs = Publisher . objects . annotate ( below_5 = below_5 ) . annotate ( above_5 = above_5 ) >>> pubs [ 0 ] . above_5 23 >>> pu ... 2026年10月08日