Skip to content

DOCSP-46425: Specify a Query #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions source/includes/interact-data/specify-a-query.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# start-models
from django.db import models
from django_mongodb_backend.models import EmbeddedModel
from django_mongodb_backend.fields import EmbeddedModelField, ArrayField

class Award(models.Model):
class Award(EmbeddedModel):
wins = models.IntegerField(default=0)
nominations = models.IntegerField(default=0)
text = models.CharField(max_length=100)
Expand Down Expand Up @@ -51,12 +52,11 @@ def __str__(self):
Movie.objects.filter(runtime__lte=50)
# end-filter-lte

# start-filter-relationships
Movie.objects.filter(awards__wins=93)
# end-filter-relationships

# start-filter-combine
Movie.objects.filter(awards__text__istartswith="nominated")
Movie.objects.filter(
(Q(title__startswith="Funny") | Q(title__startswith="Laugh"))
& ~Q(genres__contains=["Comedy"])
)
# end-filter-combine

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

# start-filter-relationships
Movie.objects.filter(awards__wins__gt=150)
# end-filter-relationships

# start-array
Movie.objects.filter(genres__overlap=["Adventure", "Family"])
# end-array

# start-json
Movie.objects.filter(imdb__votes__gt=900000)
# end-json
Expand Down
4 changes: 2 additions & 2 deletions source/interact-data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Interact with Data
.. toctree::
:caption: Interact with Data

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

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

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

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