I've been trying to use two different filter conditions having 2 different set of lists. Here, filter(condt.1)
is working and filter(condt.2)
is working; but when I use filter(condt.1).filter(condt.2)
it's working differently i.e. not working in the way I had assumed.
Here is my situation:
This one is working properly:
posts = Post.objects.filter(author__profile__in=[logged_in_user.id])
This one is also working properly:
posts = Post.objects.filter(author__profile__followers__in=[logged_in_user.id])
But I am not getting the way to combine these two filters in one. Here is what I've tried:
logged_in_user = request.user
posts = Post.objects.filter(author__profile__in=[logged_in_user.id]).filter(author__profile__followers__in=[logged_in_user.id])
If you need this filters working like
filter1 OR filter2
, you can use Q objects with|
operatorIn your example django gives you result matching both filters at the same time.