Skip to content

Instantly share code, notes, and snippets.

@coagulant
Forked from zmcghee/FakeQuerySet.py
Last active December 21, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coagulant/6277442 to your computer and use it in GitHub Desktop.
Save coagulant/6277442 to your computer and use it in GitHub Desktop.
items should not be mutable kwarg
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=None):
super(FakeQuerySet, self).__init__(model, query, using)
self._result_cache = items or []
def count(self):
return len(self)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment