from django.db.models import Count, Case, When, CharField, F
Article.objects.annotate(numviews=Count(Case(When(readership__what_time__lt
    =treshold, then=F('readership__reader')), output_field=CharField()),
    distinct=True))
How to annotate Count with a condition in a Django queryset