Reputation: 12445
Author
has the manytomany entity Article
I can use filter for manytomany like this
a = Author.objects.get(id=1)
Article.objects.filter(authors=a)
However I want to filter auther a and auther b
like
Article.objects.filter(authors=a and authors=b)
How can I make it??
Upvotes: 2
Views: 41
Reputation: 5854
try this
# for OR
from django.db.models import Q
Article.objects.filter(Q(authors=a) | Q(authors=b))
hope this helps
Upvotes: 3