I realized my question is simpler, I'm leaving the body of the previous question as further explanation. I'm having issues doing AND queries with Q objects. How does it work? I've provided 4 examples and the only time I can get it to work is when chaining filters, however I want to avoid that to build more complex queries using OR as well.
I'm having issues doing a query across relationships with Q objects when AND'ing the same queried argument.
Modifying a little bit the example on the Django documentation page: A 'Blog' model has a m2m relationship with an 'Author' model. Let's say I want to query for all the blogs that meet the following criteria: Bob and Mary are the authors or Steve is the author. I'm pretty sure the only way to do this is with Q objects, so I'm breaking it down in chunks. This is what I've attempted so far:
Blog.objects.filter(Q(author__name='bob', author__name='mary'))
returns with SyntaxError: keyword argument repeated
Blog.objects.filter(Q(author__name='bob') & Q(author__name='mary'))
returns an empty queryset
Blog.objects.filter(author__name='bob', author__name='mary')
returns with SyntaxError: keyword argument repeated
Blog.objects.filter(author__name='bob').filter(author__name='mary')
returns the correct result, however, now I lost the ability to use Q objects for the OR arguments (I believe), so I would have to do another query and have the result in 2 querysets, which is not desired
I'm not sure I explained my situation properly, or if I'm even going about it the correct way. Anybody has any advice?