I'm trying to filter a queryset by checking that the object is in a list of those objects.
employee_list = [<Employee: A>, <Employee: B>, <Employee: C>]
qs = Employee.objects.filter(id__in=employee_list, [other_filters])
After running above, qs is an empty list. I was thinking that I could make a new list such as
employee_ids = [emp.id for emp in employee_list]
qs = Employee.objects.filter(id__in=employee_ids, [other_filters])
I haven't done benchmarking on this method, but I imagine performance would probably take a hit. Alternatively I could intersect the lists afterwards like:
qs = Employee.objects.filter([other_filters])
filtered_qs = [emp for emp in employee_lids if emp in qs]
However, I think the performance hit would be even worse this way.
What's the best/fastest way to do this? Thanks.