Created
June 30, 2011 10:43
-
-
Save zmcghee/1055992 to your computer and use it in GitHub Desktop.
Fake Django QuerySet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This doesn't work in 1.6 anymore. https://docs.djangoproject.com/en/dev/releases/1.6/#miscellaneous