[Answer]-Finding posts in certain categories which you haven't voted on (django-voting, django-categories)

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'))

Leave a comment