@@ -91,7 +91,7 @@ We will use the following example model::
91
91
def __str__(self):
92
92
return self.name
93
93
94
- .. fieldlookup :: arrayfield.contains
94
+ .. fieldlookup :: mongo- arrayfield.contains
95
95
96
96
``contains ``
97
97
^^^^^^^^^^^^
@@ -134,7 +134,7 @@ passed. It uses the ``$setIntersection`` operator. For example:
134
134
>>> Post.objects.filter(tags__contained_by=["thoughts", "django", "tutorial"])
135
135
<QuerySet [<Post: First post>, <Post: Second post>, <Post: Third post>]>
136
136
137
- .. fieldlookup :: arrayfield.overlap
137
+ .. fieldlookup :: mongo- arrayfield.overlap
138
138
139
139
``overlap ``
140
140
~~~~~~~~~~~
@@ -154,7 +154,7 @@ uses the ``$setIntersection`` operator. For example:
154
154
>>> Post.objects.filter(tags__overlap=["thoughts", "tutorial"])
155
155
<QuerySet [<Post: First post>, <Post: Second post>, <Post: Third post>]>
156
156
157
- .. fieldlookup :: arrayfield.len
157
+ .. fieldlookup :: mongo- arrayfield.len
158
158
159
159
``len ``
160
160
^^^^^^^
@@ -170,7 +170,7 @@ available for :class:`~django.db.models.IntegerField`. For example:
170
170
>>> Post.objects.filter(tags__len=1)
171
171
<QuerySet [<Post: Second post>]>
172
172
173
- .. fieldlookup :: arrayfield.index
173
+ .. fieldlookup :: mongo- arrayfield.index
174
174
175
175
Index transforms
176
176
^^^^^^^^^^^^^^^^
@@ -196,7 +196,7 @@ array. The lookups available after the transform are those from the
196
196
197
197
These indexes use 0-based indexing.
198
198
199
- .. fieldlookup :: arrayfield.slice
199
+ .. fieldlookup :: mongo- arrayfield.slice
200
200
201
201
Slice transforms
202
202
^^^^^^^^^^^^^^^^
@@ -299,155 +299,6 @@ These indexes use 0-based indexing.
299
299
As described above for :class: `EmbeddedModelField `,
300
300
:djadmin: `makemigrations ` does not yet detect changes to embedded models.
301
301
302
- Querying ``EmbeddedModelArrayField ``
303
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
304
-
305
- There are a number of custom lookups and a transform for
306
- :class: `EmbeddedModelArrayField `, similar to those available
307
- for :class: `ArrayField `.
308
- We will use the following example model::
309
-
310
- from django.db import models
311
- from django_mongodb_backend.fields import EmbeddedModelArrayField
312
-
313
-
314
- class Tag(EmbeddedModel):
315
- label = models.CharField(max_length=100)
316
-
317
- class Post(models.Model):
318
- name = models.CharField(max_length=200)
319
- tags = EmbeddedModelArrayField(Tag)
320
-
321
- def __str__(self):
322
- return self.name
323
-
324
- Embedded field lookup
325
- ^^^^^^^^^^^^^^^^^^^^^
326
-
327
- Embedded field lookup for :class: `EmbeddedModelArrayField ` allow querying
328
- fields of the embedded model. This is done by composing the two involved paths:
329
- the path to the ``EmbeddedModelArrayField `` and the path within the nested
330
- embedded model.
331
- This composition enables generating the appropriate query for the lookups.
332
-
333
- .. fieldlookup :: embeddedmodelarrayfield.in
334
-
335
- ``in ``
336
- ^^^^^^
337
-
338
- Returns objects where any of the embedded documents in the field match any of
339
- the values passed. For example:
340
-
341
- .. code-block :: pycon
342
-
343
- >>> Post.objects.create(
344
- ... name="First post", tags=[Tag(label="thoughts"), Tag(label="django")]
345
- ... )
346
- >>> Post.objects.create(name="Second post", tags=[Tag(label="thoughts")])
347
- >>> Post.objects.create(
348
- ... name="Third post", tags=[Tag(label="tutorial"), Tag(label="django")]
349
- ... )
350
-
351
- >>> Post.objects.filter(tags__label__in=["thoughts"])
352
- <QuerySet [<Post: First post>, <Post: Second post>]>
353
-
354
- >>> Post.objects.filter(tags__label__in=["tutorial", "thoughts"])
355
- <QuerySet [<Post: First post>, <Post: Second post>, <Post: Third post>]>
356
-
357
- .. fieldlookup :: embeddedmodelarrayfield.len
358
-
359
- ``len ``
360
- ^^^^^^^
361
-
362
- Returns the length of the embedded model array. The lookups available afterward
363
- are those available for :class: `~django.db.models.IntegerField `. For example:
364
-
365
- .. code-block :: pycon
366
-
367
- >>> Post.objects.create(
368
- ... name="First post", tags=[Tag(label="thoughts"), Tag(label="django")]
369
- ... )
370
- >>> Post.objects.create(name="Second post", tags=[Tag(label="thoughts")])
371
-
372
- >>> Post.objects.filter(tags__len=1)
373
- <QuerySet [<Post: Second post>]>
374
-
375
- .. fieldlookup :: embeddedmodelarrayfield.exact
376
-
377
- ``exact ``
378
- ^^^^^^^^^
379
-
380
- Returns objects where **any ** embedded model in the array exactly matches the
381
- given value. This acts like an existence filter on matching embedded documents.
382
-
383
- .. code-block :: pycon
384
-
385
- >>> Post.objects.create(
386
- ... name="First post", tags=[Tag(label="thoughts"), Tag(label="django")]
387
- ... )
388
- >>> Post.objects.create(name="Second post", tags=[Tag(label="tutorial")])
389
-
390
- >>> Post.objects.filter(tags__label__exact="tutorial")
391
- <QuerySet [<Post: Second post>]>
392
-
393
- .. fieldlookup :: embeddedmodelarrayfield.iexact
394
-
395
- ``iexact ``
396
- ^^^^^^^^^^
397
-
398
- Returns objects where **any ** embedded model in the array has a field that
399
- matches the given value **case-insensitively **. This works like ``exact `` but
400
- ignores letter casing.
401
-
402
- .. code-block :: pycon
403
-
404
-
405
- >>> Post.objects.create(
406
- ... name="First post", tags=[Tag(label="Thoughts"), Tag(label="Django")]
407
- ... )
408
- >>> Post.objects.create(name="Second post", tags=[Tag(label="tutorial")])
409
-
410
- >>> Post.objects.filter(tags__label__iexact="django")
411
- <QuerySet [<Post: First post>]>
412
-
413
- >>> Post.objects.filter(tags__label__iexact="TUTORIAL")
414
- <QuerySet [<Post: Second post>]>
415
-
416
- .. fieldlookup :: embeddedmodelarrayfield.gt
417
- .. fieldlookup :: embeddedmodelarrayfield.gte
418
- .. fieldlookup :: embeddedmodelarrayfield.lt
419
- .. fieldlookup :: embeddedmodelarrayfield.lte
420
-
421
- ``Greater Than, Greater Than or Equal, Less Than, Less Than or Equal ``
422
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
423
-
424
- These lookups return objects where **any ** embedded document contains a value
425
- that satisfies the corresponding comparison. These are typically used on
426
- numeric or comparable fields within the embedded model.
427
-
428
- Examples:
429
-
430
- .. code-block :: pycon
431
-
432
- Post.objects.create(
433
- name="First post", tags=[Tag(label="django", rating=5), Tag(label="rest", rating=3)]
434
- )
435
- Post.objects.create(
436
- name="Second post", tags=[Tag(label="python", rating=2)]
437
- )
438
-
439
- Post.objects.filter(tags__rating__gt=3)
440
- <QuerySet [<Post: First post>]>
441
-
442
- Post.objects.filter(tags__rating__gte=3)
443
- <QuerySet [<Post: First post>, <Post: Second post>]>
444
-
445
- Post.objects.filter(tags__rating__lt=3)
446
- <QuerySet []>
447
-
448
- Post.objects.filter(tags__rating__lte=3)
449
- <QuerySet [<Post: First post>, <Post: Second post>]>
450
-
451
302
``ObjectIdAutoField ``
452
303
---------------------
453
304
0 commit comments