Skip to content

Commit 509823b

Browse files
committed
DOCSP-46321: CRUD operations
1 parent 4849198 commit 509823b

File tree

5 files changed

+365
-7
lines changed

5 files changed

+365
-7
lines changed

snooty.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ api = "https://django-mongodb.readthedocs.io/en/latest/"
1414
mdb-server = "MongoDB Server"
1515
django-version = "5.0"
1616
django-docs = "https://docs.djangoproject.com/en/{+django-version+}"
17+
framework = "Django"

source/includes/interact-data/crud.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# start-models
2+
from django.db import models
3+
from django_mongodb_backend.fields import ArrayField
4+
5+
class Movie(models.Model):
6+
title = models.CharField(max_length=200)
7+
plot = models.TextField(blank=True)
8+
runtime = models.IntegerField(default=0)
9+
released = models.DateTimeField("release date", null=True, blank=True)
10+
genres = ArrayField(models.CharField(max_length=100), null=True, blank=True)
11+
12+
class Meta:
13+
db_table = "movies"
14+
managed = False
15+
16+
def __str__(self):
17+
return self.title
18+
# end-models
19+
20+
# start-insert
21+
Movie.objects.create(title="Poor Things", runtime=141)
22+
# end-insert
23+
24+
# start-save
25+
movie = Movie(title="Poor Things", runtime=141)
26+
movie.save()
27+
# end-save
28+
29+
# start-find-many
30+
Movie.objects.filter(released=timezone.make_aware(datetime(2000, 1, 1)))
31+
# end-find-many
32+
33+
# start-find-one
34+
Movie.objects.get(title="Boyhood")
35+
# end-find-one
36+
37+
# start-update
38+
Movie.objects.filter(
39+
title="High Fidelity").update(
40+
plot="Rob, a record store owner, recounts his top five breakups,including the one in progress.")
41+
# end-update
42+
43+
# start-delete
44+
Movie.objects.filter(runtime=5).delete()
45+
# end-delete

source/index.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Django MongoDB Backend
1111

1212
.. toctree::
1313

14-
Issues & Help </issues-and-help>
15-
Compatibility </compatibility>
14+
Interact with Data </interact-data>
15+
Issues & Help </issues-and-help>
16+
Compatibility </compatibility>
1617

1718

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

46-
.. Interact with Data
47-
.. ------------------
46+
Interact with Data
47+
------------------
4848

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

5252
.. Model Your Data
5353
.. ---------------

source/interact-data.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _django-interact-data:
2+
3+
==================
4+
Interact with Data
5+
==================
6+
7+
.. facet::
8+
:name: genre
9+
:values: reference
10+
11+
.. meta::
12+
:keywords: odm, crud, query
13+
14+
.. toctree::
15+
:caption: Interact with Data
16+
17+
CRUD Operations </interact-data/crud>

0 commit comments

Comments
 (0)