Added API Reference to docs

This commit is contained in:
Harry Marr
2009-12-19 16:04:05 +00:00
parent 9d12dbad70
commit 8a646f0f4c
11 changed files with 101 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ import pymongo
class QuerySet(object):
"""A set of results returned from a query. Wraps a MongoDB cursor,
providing Document objects as the results.
providing :class:`~mongoengine.Document` objects as the results.
"""
def __init__(self, document, collection):
@@ -32,7 +32,8 @@ class QuerySet(object):
return self
def __call__(self, **query):
"""Filter the selected documents by calling the queryset with a query.
"""Filter the selected documents by calling the
:class:`~mongoengine.QuerySet` with a query.
"""
self._query.update(QuerySet._transform_query(**query))
return self
@@ -76,7 +77,7 @@ class QuerySet(object):
return result
def with_id(self, object_id):
"""Retrieve the object matching the _id provided.
"""Retrieve the object matching the id provided.
"""
if not isinstance(object_id, pymongo.objectid.ObjectId):
object_id = pymongo.objectid.ObjectId(object_id)
@@ -87,7 +88,7 @@ class QuerySet(object):
return result
def next(self):
"""Wrap the result in a Document object.
"""Wrap the result in a :class:`~mongoengine.Document` object.
"""
return self._document._from_son(self._cursor.next())
@@ -97,21 +98,22 @@ class QuerySet(object):
return self._cursor.count()
def limit(self, n):
"""Limit the number of returned documents to.
"""Limit the number of returned documents to `n`.
"""
self._cursor.limit(n)
# Return self to allow chaining
return self
def skip(self, n):
"""Skip n documents before returning the results.
"""Skip `n` documents before returning the results.
"""
self._cursor.skip(n)
return self
def order_by(self, *keys):
"""Order the QuerySet by the keys. The order may be specified by
prepending each of the keys by a + or a -. Ascending order is assumed.
"""Order the :class:`~mongoengine.queryset.QuerySet` by the keys. The
order may be specified by prepending each of the keys by a + or a -.
Ascending order is assumed.
"""
key_list = []
for key in keys:
@@ -126,6 +128,9 @@ class QuerySet(object):
return self
def explain(self, format=False):
"""Return an explain plan record for the
:class:`~mongoengine.queryset.QuerySet`\ 's cursor.
"""
plan = self._cursor.explain()
if format:
import pprint