1
Depends on your db. If it’s PosgtreSQL
, you will be fine with subquery.
voted_already = (Vote.objects.filter(user=…,
content_type=…)
.values_list('object_id', flat=True))
not_voted = (Post.objects.filter(category__in=…)
.exclude(author=…,
pk__in=voted_already)
.order_by('-published'))
Source:stackexchange.com