Skip to content

Commit a7004fe

Browse files
authored
DOCSP-46425: Specify a Query (#2)
* DOCSP-46425: Specify a query * DOCSP-46425: Specify a Query * more info * more * rest of page * edits * link fix * edits * edits * feedback * fixes * edits * wording * feedback * RR feedback * fixes * date * fix * use include * RR feedback 2 * embeddedmodel * test link * try again
1 parent e297b29 commit a7004fe

File tree

3 files changed

+835
-8
lines changed

3 files changed

+835
-8
lines changed

source/includes/interact-data/specify-a-query.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# start-models
22
from django.db import models
3+
from django_mongodb_backend.models import EmbeddedModel
34
from django_mongodb_backend.fields import EmbeddedModelField, ArrayField
45

5-
class Award(models.Model):
6+
class Award(EmbeddedModel):
67
wins = models.IntegerField(default=0)
78
nominations = models.IntegerField(default=0)
89
text = models.CharField(max_length=100)
@@ -51,12 +52,11 @@ def __str__(self):
5152
Movie.objects.filter(runtime__lte=50)
5253
# end-filter-lte
5354

54-
# start-filter-relationships
55-
Movie.objects.filter(awards__wins=93)
56-
# end-filter-relationships
57-
5855
# start-filter-combine
59-
Movie.objects.filter(awards__text__istartswith="nominated")
56+
Movie.objects.filter(
57+
(Q(title__startswith="Funny") | Q(title__startswith="Laugh"))
58+
& ~Q(genres__contains=["Comedy"])
59+
)
6060
# end-filter-combine
6161

6262
# start-sort
@@ -71,6 +71,14 @@ def __str__(self):
7171
Movie.objects.filter(genres=["Crime", "Comedy"]).first()
7272
# end-first
7373

74+
# start-filter-relationships
75+
Movie.objects.filter(awards__wins__gt=150)
76+
# end-filter-relationships
77+
78+
# start-array
79+
Movie.objects.filter(genres__overlap=["Adventure", "Family"])
80+
# end-array
81+
7482
# start-json
7583
Movie.objects.filter(imdb__votes__gt=900000)
7684
# end-json

source/interact-data.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ Interact with Data
2121
.. toctree::
2222
:caption: Interact with Data
2323

24+
Specify a Query </interact-data/specify-a-query>
2425
Perform Raw Queries </interact-data/raw-queries>
2526

2627
.. TODO:
2728
CRUD Operations </interact-data/crud>
28-
Specify a Query </interact-data/specify-a-query>
2929

3030
In this section, you can learn how to use {+django-odm+} to interact with your
3131
MongoDB data.
@@ -37,4 +37,4 @@ MongoDB data.
3737
your data.
3838

3939
- :ref:`django-raw-queries`: Learn how to use MongoDB's aggregation pipeline syntax
40-
or the PyMongo driver to query your data.
40+
or the PyMongo driver to query your data.

0 commit comments

Comments
 (0)