Reputation: 11
Lets say, I have a User object and I need to get a queryset with username 'foo' and 'bar'. How do i use the filter to achieve this since filter doesnot take two same kwargs.
My approach:
#obviously shows error
users=User.objects.filter(username='foo', username='bar')
What is the best way to do this?
Upvotes: 1
Views: 49
Reputation: 369444
You can use <fieldname>__in
:
users = User.objects.filter(username__in=['foo', 'bar'])
Upvotes: 1