@@ -39,6 +39,11 @@ methods:
39
39
`QuerySet API reference <https://docs.djangoproject.com/en/5.1/ref/models/querysets/>`__
40
40
in the Django documentation.
41
41
42
+ You can also use the Django admin site to edit your models
43
+ and their corresponding collections on a web interface. For
44
+ more information, see `The Django admin site <https://docs.djangoproject.com/en/5.1/ref/contrib/admin/>`__
45
+ in the Django documentation.
46
+
42
47
Sample Data
43
48
~~~~~~~~~~~
44
49
@@ -67,9 +72,17 @@ The ``Movie`` model class has the following definition:
67
72
def __str__(self):
68
73
return self.title
69
74
75
+ You can use the Python interactive shell to run the code examples.
76
+ To enter the shell, run the following command from your project's
77
+ root directory:
78
+
79
+ .. code-block:: bash
80
+
81
+ python3 manage.py shell
82
+
70
83
To learn how to create a Django application that uses the ``Movie``
71
- model to interact with MongoDB documents, visit the :ref:`django-get-started`
72
- tutorial.
84
+ model and the Python interactive shell to interact with MongoDB documents,
85
+ visit the :ref:`django-get-started` tutorial.
73
86
74
87
.. _django-crud-insert:
75
88
@@ -81,7 +94,7 @@ model objects that represent the collection. Pass the new document's fields
81
94
and values as arguments to the ``create()`` method.
82
95
83
96
Example
84
- ```````
97
+ ~~~~~~~
85
98
86
99
The following example calls the ``create()`` method on your ``Movie`` objects
87
100
to insert a document into the ``sample_mflix.movies`` collection. The new
@@ -90,9 +103,9 @@ of ``141``:
90
103
91
104
.. code-block:: python
92
105
93
- from sample_mflix.models import Movie
106
+ from sample_mflix.models import Movie
94
107
95
- movie = Movie.objects.create(title="Poor Things", runtime=141)
108
+ movie = Movie.objects.create(title="Poor Things", runtime=141)
96
109
97
110
.. note::
98
111
@@ -118,7 +131,7 @@ that matches your query.
118
131
``get()`` method, see the Specify a Query guide.
119
132
120
133
Example
121
- ```````
134
+ ~~~~~~~
122
135
123
136
The following example calls the ``filter()`` method on your ``Movie`` objects
124
137
to retrieve documents from the ``sample_mflix.movies`` collection. The query
@@ -158,7 +171,7 @@ or criteria that specifies which documents to update, as an argument to the
158
171
arguments to the ``update()`` method.
159
172
160
173
Example
161
- ```````
174
+ ~~~~~~~
162
175
163
176
The following example calls the ``update()`` method on your ``Movie`` objects
164
177
to modify documents in the ``sample_mflix.movies`` collection. The code matches
@@ -194,7 +207,7 @@ or criteria that specifies which documents to delete, as an argument to the
194
207
``filter()`` method.
195
208
196
209
Example
197
- ```````
210
+ ~~~~~~~
198
211
199
212
The following example calls the ``delete()`` method on your ``Movie`` objects
200
213
to delete documents in the ``sample_mflix.movies`` collection. The code matches
@@ -215,7 +228,7 @@ and deletes documents that have a ``runtime`` value of ``5``:
215
228
:visible: false
216
229
217
230
// Outputs the number of deleted documents and objects
218
- 16
231
+ (16, {'sample_mflix.Movie': 16})
219
232
220
233
221
234
Additional Information
@@ -227,4 +240,4 @@ To view more create, read, update, and delete examples, see the following
227
240
steps of the :ref:`django-get-started` tutorial:
228
241
229
242
- :ref:`django-get-started-write`
230
- - :ref:`django-get-started-read `
243
+ - :ref:`django-get-started-query `
0 commit comments