Avoid to open all documents from cursors in an if stmt
Using a cursos in an if statement: cursor = Collection.objects if cursor: (...) Will open all documents, because there are not an __nonzero__ method. This change check only one document (if present) and returns True or False.
This commit is contained in:
@@ -154,6 +154,15 @@ class BaseQuerySet(object):
|
||||
def __iter__(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def __nonzero__(self):
|
||||
""" Avoid to open all records in an if stmt """
|
||||
|
||||
for value in self:
|
||||
self.rewind()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
# Core functions
|
||||
|
||||
def all(self):
|
||||
|
||||
Reference in New Issue
Block a user