I have two models, authors and articles:
class Author(models.Model): name = models.CharField('name', max_length=100) class Article(models.Model) title = models.CharField('title', max_length=100) pubdate = models.DateTimeField('publication date') authors = models.ManyToManyField(Author)
Now I want to select all the authors and annotate them with my corresponding number of articles. This is a piece of cake with Django aggregates . The problem is that it should only consider articles that have already been published. According to ticket 11305 in the Django tracker guide, this is not yet possible. I tried to use the CountIf annotation mentioned on this ticket, but it does not quote the datetime string and does not make all the connections it needs.
So what is the best solution besides writing your own SQL?
source share