title: Should I iterate on django query set or over the variable?
body: <p>I have a large dataset returned from django queryset and I want to iterate over it. Should I directly iterate over the queryset or store the results in a variable and iterate over it?</p>
  
  <pre><code>for item in Model.objects.all():
      do_something()
  </code></pre>
  
  <p>or </p>
  
  <pre><code>results = Model.objects.all():
  for item in results:
      do_something()
  </code></pre>
  
  <p>As far as I know, the variables are stored in heap and its safer, where as in case of iterating over queryset, the results will be stored in main memory.</p>
  
  <p>So which one is efficient in space and speed?</p>