1👍
✅
You will have to change your code to something like this using values_list
to get only the pks in a list. Otherwise you are trying to compare a list of Post objects the exclude
code
top_posts = Post.objects.all()[:4]
top_post_pks = top_posts.values_list('pk', flat=True)
politics_posts = Post.objects.filter(category='news').exclude(pk__in=top_post_pks)
...
Also maybe you need to do category=politics
. In the question you have put category=news
Source:stackexchange.com