Skip to content

Commit 15fee18

Browse files
committed
feedback
1 parent da3ac8c commit 15fee18

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

source/interact-data/crud.txt

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ create, read, update, and delete (CRUD) operations on your MongoDB
2525
collection.
2626

2727
You can use methods provided by the Django ``QuerySet`` API to run
28-
CRUD operations. To update documents in your collection, call the
29-
``QuerySet`` operation methods on your model objects that represent the collection.
30-
Then, {+django-odm+} runs the operations on your collection documents.
28+
CRUD operations. To run these operations, call ``QuerySet`` methods
29+
your model's ``Manager``. The ``Manager`` class handles database
30+
operations and allows you to interact with your MongoDB data by referencing
31+
Django models. By default, Django adds a ``Manager`` named ``objects``
32+
to every model class.
33+
3134
This guide shows how to use the following ``QuerySet`` methods:
3235

3336
- :ref:`create() <django-crud-insert>`
@@ -57,7 +60,6 @@ The ``Movie`` model class has the following definition:
5760

5861
from django.db import models
5962
from django_mongodb_backend.fields import EmbeddedModelField, ArrayField
60-
from django_mongodb_backend.managers import MongoManager
6163

6264
class Movie(models.Model):
6365
title = models.CharField(max_length=200)
@@ -66,7 +68,6 @@ The ``Movie`` model class has the following definition:
6668
released = models.DateTimeField("release date", null=True, blank=True)
6769
awards = EmbeddedModelField(Award)
6870
genres = ArrayField(models.CharField(max_length=100), null=True, blank=True)
69-
objects = MongoManager()
7071

7172
class Meta:
7273
db_table = "movies"
@@ -83,6 +84,15 @@ root directory:
8384

8485
python manage.py shell
8586

87+
After entering the Python shell, ensure that you import the following models and
88+
modules:
89+
90+
.. code-block:: python
91+
92+
from <your application name>.models import Movie
93+
from django.utils import timezone
94+
from datetime import datetime
95+
8696
To learn how to create a Django application that uses the ``Movie``
8797
model and the Python interactive shell to interact with MongoDB documents,
8898
visit the :ref:`django-get-started` tutorial.
@@ -92,16 +102,16 @@ visit the :ref:`django-get-started` tutorial.
92102
Insert Documents
93103
----------------
94104

95-
To insert a document into a collection, call the ``create()`` method on your
96-
model objects that represent the collection. Pass the new document's fields
97-
and values as arguments to the ``create()`` method.
105+
To insert a document into a collection, call the ``create()`` method
106+
on an instance of your model's ``Manager`` class. Pass the new document's
107+
fields and values as arguments to the ``create()`` method.
98108

99109
Example
100110
~~~~~~~
101111

102-
The following example calls the ``create()`` method on your ``Movie`` objects
103-
to insert a document into the ``sample_mflix.movies`` collection. The new
104-
document has a ``title`` value of ``"Poor Things"`` and a ``runtime`` value
112+
The following example calls the ``create()`` method to insert a document
113+
into the ``sample_mflix.movies`` collection. The new document has
114+
a ``title`` value of ``"Poor Things"`` and a ``runtime`` value
105115
of ``141``:
106116

107117
.. code-block:: python
@@ -123,8 +133,8 @@ of ``141``:
123133
Read Documents
124134
--------------
125135

126-
To retrieve documents from your collection, call the ``filter()`` method on your
127-
model objects that represent the collection. Pass a query filter, or criteria
136+
To retrieve documents from your collection, call the ``filter()`` method on an
137+
instance of your model's ``Manager`` class. Pass a query filter, or criteria
128138
that specifies which documents to retrieve, as an argument to the ``filter()`` method.
129139

130140
Alternatively, you can call the ``get()`` method to retrieve a single document
@@ -133,8 +143,8 @@ that matches your query.
133143
Return Multiple Documents Example
134144
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135145

136-
The following example calls the ``filter()`` method on your ``Movie`` objects
137-
to retrieve documents from the ``sample_mflix.movies`` collection. The query
146+
The following example calls the ``filter()`` method to retrieve
147+
documents from the ``sample_mflix.movies`` collection. The query
138148
returns ``Movie`` objects that represent movies released on January 1, 2000:
139149

140150
.. io-code-block::
@@ -192,16 +202,16 @@ Modify Documents
192202
----------------
193203

194204
To modify documents in a collection, call the ``filter()`` and ``update()``
195-
methods on your model objects that represent the collection. Pass a query filter,
205+
methods on an instance of your model's ``Manager`` class. Pass a query filter,
196206
or criteria that specifies which documents to update, as an argument to the
197207
``filter()`` method. Then, pass the fields and values you want to update as
198208
arguments to the ``update()`` method.
199209

200210
Example
201211
~~~~~~~
202212

203-
The following example calls the ``update()`` method on your ``Movie`` objects
204-
to modify documents in the ``sample_mflix.movies`` collection. The code matches
213+
The following example calls the ``update()`` method to modify
214+
documents in the ``sample_mflix.movies`` collection. The code matches
205215
a document that has a ``title`` value of ``"High Fidelity"`` and adds a
206216
``plot`` field:
207217

@@ -229,15 +239,15 @@ Delete Documents
229239
----------------
230240

231241
To delete documents in a collection, call the ``filter()`` and ``delete()``
232-
methods on your model objects that represent the collection. Pass a query filter,
242+
methods on an instance of your model's ``Manager`` class. Pass a query filter,
233243
or criteria that specifies which documents to delete, as an argument to the
234244
``filter()`` method.
235245

236246
Example
237247
~~~~~~~
238248

239-
The following example calls the ``delete()`` method on your ``Movie`` objects
240-
to delete documents in the ``sample_mflix.movies`` collection. The code matches
249+
The following example calls the ``delete()`` method to delete documents
250+
in the ``sample_mflix.movies`` collection. The code matches
241251
and deletes documents that have a ``runtime`` value of ``5``:
242252

243253
.. io-code-block::

0 commit comments

Comments
 (0)