[Django]-Annotate a count of a related field

3👍

You just use the lower-case name of the related model, as you do when following a relationship backwards in a query:

Domain.objects.all().annotate(rentalextra_set_count=Count('rentalextra'))

Leave a comment