How to implement the having clause in sqlite django ORM How to implement the having clause in sqlite django ORM sqlite sqlite

How to implement the having clause in sqlite django ORM


Finally I've managed to figure it out. The ORM syntax is something like this.

from django.db.models.aggregates import CountJobStatus.objects.filter(    status='PRF').values_list(    'job', flat=True).order_by(    'job').annotate(    count_status=Count('status')).filter(    count_status__gt=1).distinct()


More general rule for this: you need to create new column (by annotate) and then filter through that new column. This queryset will be transformed to HAVING keyword.