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 24 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
1 change: 1 addition & 0 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ api = "https://django-mongodb.readthedocs.io/en/latest/"
mdb-server = "MongoDB Server"
django-version = "5.0"
django-docs = "https://docs.djangoproject.com/en/{+django-version+}"
framework = "Django"
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
25 changes: 25 additions & 0 deletions source/includes/use-sample-data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The |model-classes| an inner ``Meta`` class, which specifies
model metadata, and a ``__str__()`` method, which sets the
model's string representation to its ``title`` field. To learn about
these model features, see :ref:`django-models-define` in the
Create Models guide.

Run Code Examples
`````````````````

You can use the Python interactive shell to run the code examples.
To enter the shell, run the following command from your project's
root directory:

.. code-block:: bash

python manage.py shell

After entering the Python shell, ensure that you import the following models and
modules:

|model-imports|

To learn how to create a {+framework+} application that uses the ``Movie``
model and the Python interactive shell to interact with MongoDB documents,
visit the :ref:`django-get-started` tutorial.
11 changes: 5 additions & 6 deletions source/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ Django MongoDB Backend

.. toctree::

Interact with Data </interact-data>
Issues & Help </issues-and-help>
Compatibility </compatibility>


.. TODO:
Get Started </get-started>
Connection Configuration </connect>
Interact with Data </interact-data>
Model Your Data </model-data>
Django Feature Limitations </feature-limitations>
API Documentation <{+api+}>
Expand All @@ -43,11 +42,11 @@ a Django database backend that uses PyMongo to connect to MongoDB.
.. Learn how to configure a connection to a MongoDB deployment
in the :ref:`django-connection-configuration` section.

.. Interact with Data
.. ------------------
Interact with Data
------------------

.. Learn how to use {+django-odm+} to perform operations on MongoDB data
in the :ref:`django-interact-data` section.
Learn how to use {+django-odm+} to perform operations on MongoDB data
in the :ref:`django-interact-data` section.

.. Model Your Data
.. ---------------
Expand Down
17 changes: 17 additions & 0 deletions source/interact-data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _django-interact-data:

==================
Interact with Data
==================

.. facet::
:name: genre
:values: reference

.. meta::
:keywords: odm, crud, query

.. toctree::
:caption: Interact with Data

Specify a Query </interact-data/specify-a-query>
Loading
Loading