@@ -168,9 +168,10 @@ The following table describes supported BSON field types and their
168
168
in this guide.
169
169
170
170
* - ``Object``
171
- - ``EmbeddedModelField``
172
- - | Stores embedded documents. To learn more about using this field
173
- with {+django-odm+}, see the :ref:`django-models-embedded` section in this guide.
171
+ - ``EmbeddedModelField`` or ``EmbeddedModelArrayField``
172
+ - | Stores one or multiple embedded documents. To learn more about using these fields
173
+ with {+django-odm+}, see the :ref:`django-models-embedded` and :ref:`django-models-embedded-array`
174
+ sections.
174
175
175
176
* - ``ObjectId``
176
177
- ``ObjectIdField``
@@ -452,6 +453,36 @@ and modifies the ``Movie`` model to include the ``EmbeddedModelField``:
452
453
To learn how to query data stored in an ``EmbeddedModelField``, see
453
454
:ref:`django-query-embedded` in the Specify a Query guide.
454
455
456
+ .. _django-models-embedded-array:
457
+
458
+ Use an EmbeddedModelArrayField
459
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
460
+
461
+ You can use an ``EmbeddedModelArrayField`` to represent a MongoDB document
462
+ field that stores an array of documents in a one-to-many relationship. Each
463
+ document in the array corresponds to a {+django-odm+} ``EmbeddedModelField`` value. To create an ``EmbeddedModelArrayField``,
464
+ use the ``EmbeddedModelArrayField()`` class constructor and pass the following arguments:
465
+
466
+ - ``embedded_model``: Specifies the model stored in each array item.
467
+
468
+ - ``max_size``: *(Optional)* Specifies the maximum size of the array.
469
+
470
+ Example
471
+ ```````
472
+
473
+ This example adds an ``EmbeddedModelArrayField`` value to the model created in
474
+ the :ref:`Define a Model example <django-models-define-ex>` in this
475
+ guide. This ``cast`` field stores an array of embedded ``Actor`` models.
476
+ The following code defines the ``Actor`` model and modifies the ``Movie`` model
477
+ to include the ``EmbeddedModelArrayField``:
478
+
479
+ .. literalinclude:: /includes/model-data/models.py
480
+ :start-after: start-embedded-array-field
481
+ :end-before: end-embedded-array-field
482
+ :language: python
483
+ :copyable:
484
+ :emphasize-lines: 5, 15
485
+
455
486
Additional Information
456
487
----------------------
457
488
0 commit comments