Skip to content

Instantly share code, notes, and snippets.

View coagulant's full-sized avatar

Ilya Baryshev coagulant

View GitHub Profile
@coagulant
coagulant / FakeQuerySet.py
Last active December 21, 2015 08:19 — forked from zmcghee/FakeQuerySet.py
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)