Is it possible to have "conditional" annotation in Django? Let's say, there are following models
class Author(models.Model):
name = models.CharField()
class Article(models.Model):
title = models.CharField()
published = models.BooleanField()
now I'd like to select some limited (filtered) queryset of authors, and annotate them with both total books count and published books count, for later usage (like applying filters on the authors queryset, or ordering it). Something like
Author.objects.filter(name__icontains = 'a').annotate(total_books = Count('books')).annotate(published_books = Count('books', <here published=true filter>))
Is that possible anyhow?