The Python Oracle

Django -- How to filter objects with an "author" from a set of "authors"(users)?

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Breezy Bay

--

Chapters
00:00 Django -- How To Filter Objects With An &Quot;Author&Quot; From A Set Of &Quot;Authors&Quot;(Users)?
01:16 Accepted Answer Score 6
01:38 Answer 2 Score 5
01:44 Answer 3 Score 0
01:48 Thank you

--

Full question
https://stackoverflow.com/questions/2356...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #database #django #djangomodels

#avk47



ACCEPTED ANSWER

Score 6


Something like:

Post.objects.filter(author=user)

Where user is the relevant user should work, but it's hard to give a good answer with no models

EDIT

Now that I understand your question, try this:

Post.objects.filter(author__in=users)

Where users is the set of users




ANSWER 2

Score 5


Post.objects.filter(author__in=setofusers)



ANSWER 3

Score 0


Post.objects.filter(attribute__in = list_of_ids)