Skip to content

Instantly share code, notes, and snippets.

@zmcghee
Created June 30, 2011 10:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zmcghee/1055992 to your computer and use it in GitHub Desktop.
Save zmcghee/1055992 to your computer and use it in GitHub Desktop.
Fake Django QuerySet
from django.db.models.query import EmptyQuerySet
class FakeQuerySet(EmptyQuerySet):
"""Turn a list into a Django QuerySet... kind of."""
def __init__(self, model=None, query=None, using=None, items=[]):
super(FakeQuerySet, self).__init__(model, query, using)
self._result_cache = items
def count(self):
return len(self)
@lukasklein
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment