[Fixed]-Inefficient database query inside a for loop

1👍

First: if something=elem condition does not match any object, you won’t get None, someModel will raise a DoesNotExist exception.

Second, you could try this:

return_list = someModel.objects.filter(something__in=elemList)
return return_list
👤Gocht

Leave a comment