Skip to content

DOCSP-46325: Models #9

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 13 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 11 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
5 changes: 4 additions & 1 deletion snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ intersphinx = [ "https://www.mongodb.com/docs/manual/objects.inv",
"https://www.mongodb.com/docs/atlas/objects.inv"
]

# toc_landing_pages = ["/paths/to/pages/that/have/nested/content"]
toc_landing_pages = [
"/model-data"
]

[constants]
django-odm = "Django MongoDB Backend"
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"
85 changes: 85 additions & 0 deletions source/includes/model-data/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# start-models
from django.db import models

class Movie(models.Model):
title = models.CharField(max_length=200)
plot = models.TextField(blank=True)
runtime = models.IntegerField(default=0)
released = models.DateTimeField("release date", null=True, blank=True)

class Meta:
db_table = "movies"
managed = False

def __str__(self):
return self.title
# end-models

# start-json-field
from django.db import models

class Movie(models.Model):
title = models.CharField(max_length=200)
plot = models.TextField(blank=True)
runtime = models.IntegerField(default=0)
released = models.DateTimeField("release date", null=True, blank=True)
imdb = models.JSONField(null=True, blank=True)

class Meta:
db_table = "movies"
managed = False

def __str__(self):
return self.title
# end-json-field

# start-array-field
from django.db import models
from django_mongodb_backend.fields import ArrayField

class Movie(models.Model):
title = models.CharField(max_length=200)
plot = models.TextField(blank=True)
runtime = models.IntegerField(default=0)
released = models.DateTimeField("release date", null=True, blank=True)
genres = ArrayField(
models.CharField(max_length=100),
size=5,
null=True,
blank=True)

class Meta:
db_table = "movies"
managed = False

def __str__(self):
return self.title
# end-array-field

# start-embedded-field
from django.db import models
from django_mongodb_backend.models import EmbeddedModel
from django_mongodb_backend.fields import EmbeddedModelField

class Award(EmbeddedModel):
wins = models.IntegerField(default=0)
nominations = models.IntegerField(default=0)
text = models.CharField(max_length=100)

class Meta:
managed = False

class Movie(models.Model):
title = models.CharField(max_length=200)
plot = models.TextField(blank=True)
runtime = models.IntegerField(default=0)
released = models.DateTimeField("release date", null=True, blank=True)
awards = EmbeddedModelField(Award, null=True, blank=True)

class Meta:
db_table = "movies"
managed = False

def __str__(self):
return self.title
# end-embedded-field
10 changes: 5 additions & 5 deletions source/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Django MongoDB Backend

.. toctree::

Model Your Data </model-data>
Issues & Help </issues-and-help>
Compatibility </compatibility>

Expand All @@ -19,7 +20,6 @@ Django MongoDB Backend
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 Down Expand Up @@ -49,11 +49,11 @@ a Django database backend that uses PyMongo to connect to MongoDB.
.. Learn how to use {+django-odm+} to perform operations on MongoDB data
in the :ref:`django-interact-data` section.

.. Model Your Data
.. ---------------
Model Your Data
---------------

.. Learn how to create Django models that represent MongoDB collections
in the :ref:`django-model-data` section.
Learn how to create Django models that represent MongoDB collections
in the :ref:`django-model-data` section.

.. Django Feature Limitations
.. --------------------------
Expand Down
25 changes: 25 additions & 0 deletions source/model-data.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming there are more pages to come that will be nested here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, the indexes page will also go here

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. _django-model-data:

===============
Model Your Data
===============

.. contents:: On this page
:local:
:backlinks: none
:depth: 2
:class: singlecol

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

.. meta::
:description: Learn how to use Django MongoDB Backend to model MongoDB data.
:keywords: field, query, collection, object

.. toctree::
:titlesonly:
:maxdepth: 1

Create Models </model-data/models>
Loading
Loading