Added indexes and Django use to docs
This commit is contained in:
parent
ef5815e4a5
commit
960aea2fd4
29
docs/django.rst
Normal file
29
docs/django.rst
Normal file
@ -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.
|
@ -168,6 +168,22 @@ The following example shows a :class:`Log` document that will be limited to
|
|||||||
ip_address = StringField()
|
ip_address = StringField()
|
||||||
meta = {'max_documents': 1000, 'max_size': 2000000}
|
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
|
Document inheritance
|
||||||
--------------------
|
--------------------
|
||||||
To create a specialised type of a :class:`~mongoengine.Document` you have
|
To create a specialised type of a :class:`~mongoengine.Document` you have
|
||||||
|
@ -44,6 +44,11 @@ class Document(BaseDocument):
|
|||||||
maximum size of the collection in bytes. If :attr:`max_size` is not
|
maximum size of the collection in bytes. If :attr:`max_size` is not
|
||||||
specified and :attr:`max_documents` is, :attr:`max_size` defaults to
|
specified and :attr:`max_documents` is, :attr:`max_size` defaults to
|
||||||
10000000 bytes (10MB).
|
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
|
__metaclass__ = TopLevelDocumentMetaclass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user