gwu-libraries/DigOp — Issue #11: pass QuerySets to views instead of building lists 
Author: dchud
Created: 2012-02-21 16:27:36+00:00
State: open

in views.indexPage there's code that builds an in-memory list from a query result, then passing that to the view:

```
bs = list(User.objects.all())
...
'list' : myList,
```

Django's querysets are optimized for lazy loading and with features that make them easy to use in views or to further refine queries. Assigning the results to a list can be memory-intensive and loses the availability of those features. Instead, in this case you could do either:

```
'users': User.objects.all()
```
...if you want to do it all in one line, or:

```
users = User.objects.all()
...
'users': users,
```
...if you might want to run additional queries off of ```users``` while you have the QuerySet.