I\'m trying to improve some existing code which originally took 3 minutes to prepare a large dataTable (then returned by Ajax). The old code iterated over a large querySet,
iterating over querysets is generally a bad idea, because SQL is executed for each item
That's not true. Below is taken from the official docs:
A QuerySet is iterable, and it executes its database query the first time you iterate over it
I think the problem has to do with the definition of the users from your code. What did you assign to it?