Added no_dereference context manager (#82)
Reorganised the context_managers as well
This commit is contained in:
@@ -7,7 +7,6 @@ Connecting
|
||||
|
||||
.. autofunction:: mongoengine.connect
|
||||
.. autofunction:: mongoengine.register_connection
|
||||
.. autoclass:: mongoengine.SwitchDB
|
||||
|
||||
Documents
|
||||
=========
|
||||
@@ -35,6 +34,13 @@ Documents
|
||||
.. autoclass:: mongoengine.ValidationError
|
||||
:members:
|
||||
|
||||
Context Managers
|
||||
================
|
||||
|
||||
.. autoclass:: mongoengine.context_managers.switch_db
|
||||
.. autoclass:: mongoengine.context_managers.no_dereference
|
||||
.. autoclass:: mongoengine.context_managers.query_counter
|
||||
|
||||
Querying
|
||||
========
|
||||
|
||||
|
||||
@@ -32,8 +32,9 @@ Changes in 0.8.X
|
||||
- Fixed inheritance and unique index creation (#140)
|
||||
- Fixed reverse delete rule with inheritance (#197)
|
||||
- Fixed validation for GenericReferences which havent been dereferenced
|
||||
- Added SwitchDB context manager (#106)
|
||||
- Added switch_db context manager (#106)
|
||||
- Added switch_db method to document instances (#106)
|
||||
- Added no_dereference context manager (#82)
|
||||
|
||||
Changes in 0.7.9
|
||||
================
|
||||
|
||||
@@ -75,15 +75,15 @@ Switch Database Context Manager
|
||||
===============================
|
||||
|
||||
Sometimes you might want to switch the database to query against for a class.
|
||||
The SwitchDB context manager allows you to change the database alias for a
|
||||
class eg ::
|
||||
The :class:`~mongoengine.context_managers.switch_db` context manager allows
|
||||
you to change the database alias for a class eg ::
|
||||
|
||||
from mongoengine import SwitchDB
|
||||
from mongoengine.context_managers import switch_db
|
||||
|
||||
class User(Document):
|
||||
name = StringField()
|
||||
|
||||
meta = {"db_alias": "user-db"}
|
||||
|
||||
with SwitchDB(User, 'archive-user-db') as User:
|
||||
with switch_db(User, 'archive-user-db') as User:
|
||||
User(name="Ross").save() # Saves the 'archive-user-db'
|
||||
|
||||
@@ -93,7 +93,7 @@ may used with :class:`~mongoengine.GeoPointField`\ s:
|
||||
[(41.91,-87.69), (41.92,-87.68), (41.91,-87.65), (41.89,-87.65)]).
|
||||
.. note:: Requires Mongo Server 2.0
|
||||
* ``max_distance`` -- can be added to your location queries to set a maximum
|
||||
distance.
|
||||
distance.
|
||||
|
||||
|
||||
Querying lists
|
||||
@@ -369,6 +369,22 @@ references to the depth of 1 level. If you have more complicated documents and
|
||||
want to dereference more of the object at once then increasing the :attr:`max_depth`
|
||||
will dereference more levels of the document.
|
||||
|
||||
Turning off dereferencing
|
||||
-------------------------
|
||||
|
||||
Sometimes for performance reasons you don't want to automatically dereference
|
||||
data . To turn off all dereferencing you can use the
|
||||
:class:`~mongoengine.context_managers.no_dereference` context manager::
|
||||
|
||||
with no_dereference(Post) as Post:
|
||||
post = Post.objects.first()
|
||||
assert(isinstance(post.author, ObjectId))
|
||||
|
||||
.. note::
|
||||
|
||||
:class:`~mongoengine.context_managers.no_dereference` only works on the
|
||||
Default QuerySet manager.
|
||||
|
||||
Advanced queries
|
||||
================
|
||||
Sometimes calling a :class:`~mongoengine.queryset.QuerySet` object with keyword
|
||||
|
||||
Reference in New Issue
Block a user