Hey Edre,
It’s possible that the implementation vary between db vendors. In PostgreSQL both work as expected:

>>> print( User.objects.annotate(cnt=Count('id', filter=F('is_active'))).values('cnt').query )                                                   
SELECT COUNT("auth_user"."id") FILTER (WHERE "auth_user"."is_active") AS "cnt" FROM "auth_user" GROUP BY "auth_user"."id"
>>> print( User.objects.annotate(cnt=Count('id', filter=Q(is_active=True))).values('cnt').query )
SELECT COUNT("auth_user"."id") FILTER (WHERE "auth_user"."is_active" = True) AS "cnt" FROM "auth_user" GROUP BY "auth_user"."id"

If SQLite is unable to evaluate is_active you might need to use Q.

Written by

Full Stack Developer, Team Leader, Independent. More from me at https://hakibenita.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store