@@ -29,7 +29,7 @@ CRUD operations. This guide shows how to use the following ``QuerySet``
2929methods:
3030
3131- :ref:`create() <django-crud-insert>`
32- - :ref:`filter() <django-crud-read>`
32+ - :ref:`filter() and get() <django-crud-read>`
3333- :ref:`update() <django-crud-modify>`
3434- :ref:`delete() <django-crud-delete>`
3535
@@ -127,11 +127,8 @@ that specifies which documents to retrieve, as an argument to the ``filter()`` m
127127Alternatively, you can call the ``get()`` method to retrieve a single document
128128that matches your query.
129129
130- .. TODO: (add to the previous paragraph) To view an example that calls the
131- ``get()`` method, see the Specify a Query guide.
132-
133- Example
134- ~~~~~~~
130+ Return Multiple Documents Example
131+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135132
136133The following example calls the ``filter()`` method on your ``Movie`` objects
137134to retrieve documents from the ``sample_mflix.movies`` collection. The query
@@ -158,6 +155,34 @@ returns ``Movie`` objects that represent movies released on January 1, 2000:
158155 <Movie: First Person Plural>, <Movie: Just, Melvin: Just Evil>, <Movie: Sound and Fury>,
159156 <Movie: Peppermint Candy>]>
160157
158+ Return One Document Example
159+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160+
161+ To retrieve only one document that matches your query criteria, call the
162+ ``get()`` method and pass a query filter as an argument. The following example
163+ retrieves a document in which the ``title`` value is ``"Boyhood"``:
164+
165+ .. io-code-block::
166+ :copyable: true
167+
168+ .. input::
169+ :language: python
170+
171+ from sample_mflix.models import Movie
172+
173+ Movie.objects.get(title="Boyhood")
174+
175+ .. output::
176+ :language: none
177+ :visible: false
178+
179+ <Movie: Boyhood>
180+
181+ .. note::
182+
183+ If your query matches no documents or multiple documents, the ``get()``
184+ method generates an error. To retrieve one document from a query
185+ that might match multiple, chain the ``first()`` method to ``filter()``.
161186
162187.. _django-crud-modify:
163188
0 commit comments