4👍
✅
Your current query is trying to find employees which have department id 18 and 19 and 20. If department
is a foreign key, that is not possible.
You can use Q()
objects to find employees which have department id 18 or 19 or 20.
Employee.objects.filter(Q(department=18)|Q(department=19)|Q(department=20))
However in your case, the simplest solution is to use __in
to return employees where the department id is any one of 18, 19 or 20.
Employee.objects.filter(department__in=[18, 19, 20])
Source:stackexchange.com