1
I think you better query in reverse: with .values(…)
you select a specific database column, so this will omit the model logic.
You can retrieve the categories with:
Category.objects.filter(posts__is_published=True).distinct()
Source:stackexchange.com