diff --git a/docs/django.rst b/docs/django.rst new file mode 100644 index 00000000..57684365 --- /dev/null +++ b/docs/django.rst @@ -0,0 +1,29 @@ +============================= +Using MongoEngine with Django +============================= + +Connecting +========== +In your **settings.py** file, ignore the standard database settings (unless you +also plan to use the ORM in your project), and instead call +:func:`~mongoengine.connect` somewhere in the settings module. + +Authentication +============== +MongoEngine includes a Django authentication backend, which uses MongoDB. The +:class:`~mongoengine.django.auth.User` model is a MongoEngine +:class:`~mongoengine.Document`, but implements most of the methods and +attributes that the standard Django :class:`User` model does - so the two are +moderately compatible. Using this backend will allow you to store users in +MongoDB but still use many of the Django authentication infrastucture (such as +the :func:`login_required` decorator and the :func:`authenticate` function). To +enable the MongoEngine auth backend, add the following to you **settings.py** +file:: + + AUTHENTICATION_BACKENDS = ( + 'mongoengine.django.auth.MongoEngineBackend', + ) + +The :mod:`~mongoengine.django.auth` module also contains a +:func:`~mongoengine.django.auth.get_user` helper function, that takes a user's +:attr:`id` and returns a :class:`~mongoengine.django.auth.User` object. diff --git a/docs/userguide.rst b/docs/userguide.rst index c1dd13ae..602d51b6 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -168,6 +168,22 @@ The following example shows a :class:`Log` document that will be limited to ip_address = StringField() meta = {'max_documents': 1000, 'max_size': 2000000} +Indexes +------- +You can specify indexes on collections to make querying faster. This is done +by creating a list of index specifications called :attr:`indexes` in the +:attr:`~Document.meta` dictionary, where an index specification may either be +a single field name, or a tuple containing multiple field names. A direction +may be specified on fields by prefixing the field name with a **+** or a **-** +sign. Note that direction only matters on multi-field indexes. :: + + class Page(Document): + title = StringField() + rating = StringField() + meta = { + 'indexes': ['title', ('title', '-rating')] + } + Document inheritance -------------------- To create a specialised type of a :class:`~mongoengine.Document` you have diff --git a/mongoengine/document.py b/mongoengine/document.py index d7154404..1afa1e41 100644 --- a/mongoengine/document.py +++ b/mongoengine/document.py @@ -44,6 +44,11 @@ class Document(BaseDocument): maximum size of the collection in bytes. If :attr:`max_size` is not specified and :attr:`max_documents` is, :attr:`max_size` defaults to 10000000 bytes (10MB). + + Indexes may be created by specifying :attr:`indexes` in the :attr:`meta` + dictionary. The value should be a list of field names or tuples of field + names. Index direction may be specified by prefixing the field names with + a **+** or **-** sign. """ __metaclass__ = TopLevelDocumentMetaclass