added QuerySet.only

This commit is contained in:
blackbrrr 2010-02-23 00:24:28 -06:00
parent 3762a69537
commit 8b1a39f2c1

View File

@ -120,6 +120,7 @@ class QuerySet(object):
self._accessed_collection = False
self._query = {}
self._where_clause = None
self._loaded_fields = []
# If inheritance is allowed, only return instances and instances of
# subclasses of the class being used
@ -220,7 +221,11 @@ class QuerySet(object):
@property
def _cursor(self):
if self._cursor_obj is None:
self._cursor_obj = self._collection.find(self._query)
cursor_args = {}
if self._loaded_fields:
cursor_args = {'fields': self._loaded_fields}
self._cursor_obj = self._collection.find(self._query,
**cursor_args)
# Apply where clauses to cursor
if self._where_clause:
self._cursor_obj.where(self._where_clause)
@ -430,6 +435,10 @@ class QuerySet(object):
elif isinstance(key, int):
return self._document._from_son(self._cursor[key])
def only(self, *fields):
self._loaded_fields = list(fields)
return self
def order_by(self, *keys):
"""Order the :class:`~mongoengine.queryset.QuerySet` by the keys. The
order may be specified by prepending each of the keys by a + or a -.