Skip to content

Instantly share code, notes, and snippets.

@funvit
Forked from zmcghee/FakeQuerySet.py
Created August 29, 2013 15:16
Show Gist options
  • Select an option

  • Save funvit/6379416 to your computer and use it in GitHub Desktop.

Select an option

Save funvit/6379416 to your computer and use it in GitHub Desktop.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment