Skip to content

Commit 6ba78c3

Browse files
committed
Restructure docs per Diátaxis framework
Add intro, reference, and topic sections.
1 parent f5dbacb commit 6ba78c3

20 files changed

+560
-21
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ explore and build. The best way to share this is via our [MongoDB Community Foru
1010
* [Model Your Data](https://www.mongodb.com/docs/languages/python/django-mongodb/current/model-data/)
1111
* [Limitations & Future Work](https://www.mongodb.com/docs/languages/python/django-mongodb/current/limitations-upcoming/)
1212

13+
The documentation in the "docs" directory is online at
14+
https://django-mongodb-backend.readthedocs.io/en/latest/.
15+
1316
## Install
1417

1518
Use the version of `django-mongodb-backend` that corresponds to your version of

docs/source/conf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# documentation root, use os.path.abspath to make it absolute, like shown here.
1717
sys.path.append(str((Path(__file__).parent / "_ext").resolve()))
1818

19-
project = "django_mongodb_backend"
20-
copyright = "2024, The MongoDB Python Team"
19+
project = "Django MongoDB Backend"
20+
copyright = "2025, The MongoDB Python Team"
2121
author = "The MongoDB Python Team"
2222
release = _version("django_mongodb_backend")
2323

@@ -39,12 +39,15 @@
3939
intersphinx_mapping = {
4040
"django": (
4141
"https://docs.djangoproject.com/en/5.1/",
42-
"http://docs.djangoproject.com/en/5.1/_objects/",
42+
"https://docs.djangoproject.com/en/5.1/_objects/",
4343
),
44+
"mongodb": ("https://www.mongodb.com/docs/languages/python/django-mongodb/v5.1/", None),
4445
"pymongo": ("https://pymongo.readthedocs.io/en/stable/", None),
4546
"python": ("https://docs.python.org/3/", None),
4647
}
4748

49+
root_doc = "contents"
50+
4851
# -- Options for HTML output -------------------------------------------------
4952
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
5053

docs/source/contents.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=================
2+
Table of contents
3+
=================
4+
5+
.. toctree::
6+
:hidden:
7+
8+
index
9+
10+
.. toctree::
11+
:maxdepth: 2
12+
13+
intro/index
14+
topics/index
15+
ref/index
16+
faq
17+
internals
18+
19+
Indices
20+
=======
21+
22+
* :ref:`genindex`
23+
* :ref:`modindex`

docs/source/faq.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
===
2+
FAQ
3+
===
4+
5+
This page contains a list of some frequently asked questions.
6+
7+
Troubleshooting
8+
===============
9+
10+
Debug logging
11+
-------------
12+
13+
To troubleshoot MongoDB connectivity issues, you can enable :doc:`PyMongo's
14+
logging <pymongo:examples/logging>` using :doc:`Django's LOGGING setting
15+
<django:topics/logging>`.
16+
17+
This is a minimal :setting:`LOGGING` setting that enables PyMongo's ``DEBUG``
18+
logging::
19+
20+
LOGGING = {
21+
"version": 1,
22+
"disable_existing_loggers": False,
23+
"handlers": {
24+
"console": {
25+
"class": "logging.StreamHandler",
26+
},
27+
},
28+
"loggers": {
29+
"pymongo": {
30+
"handlers": ["console"],
31+
"level": "DEBUG",
32+
},
33+
},
34+
}

docs/source/index.rst

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,48 @@
1-
django-mongodb-backend 5.1.x documentation
2-
==========================================
1+
======================
2+
Django MongoDB Backend
3+
======================
34

4-
.. toctree::
5-
:maxdepth: 1
6-
:caption: Contents:
5+
version 5.1.x for Django 5.1.x
76

8-
fields
9-
querysets
10-
forms
11-
models
12-
embedded-models
7+
.. rubric:: Everything you need to know about Django MongoDB Backend.
138

14-
Indices and tables
15-
==================
9+
First steps
10+
===========
1611

17-
* :ref:`genindex`
18-
* :ref:`modindex`
19-
* :ref:`search`
12+
**Getting started:**
13+
14+
- :doc:`Installation <intro/install>`
15+
- :doc:`Configuration <intro/configure>`
16+
17+
Getting help
18+
============
19+
20+
Having trouble? We’d like to help!
21+
22+
- Try the :doc:`faq` – it’s got answers to many common questions.
23+
24+
- Looking for specific information? Try the :ref:`genindex`, :ref:`modindex`,
25+
or the detailed :doc:`table of contents <contents>`.
26+
27+
- Didn't find an answer? You're welcome to ask questions or give feedback on
28+
the `MongoDB Community Forum <https://www.mongodb.com/community/forums/tag/python>`_.
29+
30+
- Report bugs and request features in our :ref:`issue tracker <issue-tracker>`.
31+
32+
Models
33+
======
34+
35+
**Reference material:**
36+
37+
- :doc:`ref/models/fields`
38+
- :doc:`ref/models/querysets`
39+
- :doc:`ref/models/models`
40+
41+
**Topic guides:**
42+
43+
- :doc:`topics/embedded-models`
44+
45+
Forms
46+
=====
47+
48+
- :doc:`ref/forms`

docs/source/internals.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=================
2+
Project internals
3+
=================
4+
5+
Documentation for people working on Django MongoDB Backend itself. This is the
6+
place to go if you'd like to help improve Django MongoDB Backend or learn about
7+
how the project is managed.
8+
9+
.. _issue-tracker:
10+
11+
Issue tracker
12+
=============
13+
14+
To report a bug or to request a new feature in Django MongoDB Backend, please
15+
open an issue in our issue tracker, JIRA:
16+
17+
1. Create a `JIRA account <https://jira.mongodb.org/>`_.
18+
19+
2. Navigate to the `Python Integrations project
20+
<https://jira.mongodb.org/projects/INTPYTHON/>`_.
21+
22+
3. Click **Create Issue**. Please provide as much information as possible about
23+
the issue and the steps to reproduce it.
24+
25+
Bug reports in JIRA for this project can be viewed by everyone.

docs/source/intro/configure.rst

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
===================================================
2+
Configuring a project to use Django MongoDB Backend
3+
===================================================
4+
5+
Aftering :doc:`installing Django MongoDB Backend <install>`, you must take some
6+
additional steps to configure your project.
7+
8+
.. _specifying the-default-pk-field:
9+
10+
Specifying the default primary key field
11+
========================================
12+
13+
In your Django settings, you must specify that all models should use
14+
:class:`~django_mongodb_backend.fields.ObjectIdAutoField`.
15+
16+
You can create a new project that's configured based on these steps using a
17+
project template:
18+
19+
.. code-block:: bash
20+
21+
$ django-admin startproject mysite --template https://github.com/mongodb-labs/django-mongodb-project/archive/refs/heads/5.1.x.zip
22+
23+
(If you're using a version of Django other than 5.1.x, replace the two numbers
24+
to match the first two numbers from your version.)
25+
26+
This template includes the following line in ``settings.py``::
27+
28+
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
29+
30+
But this setting won't override any apps that have an ``AppConfig`` that
31+
specifies :attr:`~django.apps.AppConfig.default_auto_field`. For those apps,
32+
you'll need to create a custom :class:`~django.apps.AppConfig`.
33+
34+
For example, the project template includes ``<project_name>/apps.py``::
35+
36+
from django.contrib.admin.apps import AdminConfig
37+
from django.contrib.auth.apps import AuthConfig
38+
from django.contrib.contenttypes.apps import ContentTypesConfig
39+
40+
41+
class MongoAdminConfig(AdminConfig):
42+
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
43+
44+
45+
class MongoAuthConfig(AuthConfig):
46+
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
47+
48+
49+
class MongoContentTypesConfig(ContentTypesConfig):
50+
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
51+
52+
Each app reference in the :setting:`INSTALLED_APPS` setting must point to the
53+
corresponding ``AppConfig``. For example, instead of ``'django.contrib.admin'``,
54+
the template uses ``'<project_name>.apps.MongoAdminConfig'``.
55+
56+
Configuring migrations
57+
======================
58+
59+
Because all models must use
60+
:class:`~django_mongodb_backend.fields.ObjectIdAutoField`, each third-party
61+
and contrib app you use needs to have its own migrations specific to MongoDB.
62+
63+
For example, ``settings.py`` in the project template specifies::
64+
65+
MIGRATION_MODULES = {
66+
"admin": "mongo_migrations.admin",
67+
"auth": "mongo_migrations.auth",
68+
"contenttypes": "mongo_migrations.contenttypes",
69+
}
70+
71+
The project template includes these migrations, but you can generate them if
72+
you're setting things up manually or if you need to create migrations for
73+
third-party apps. For example:
74+
75+
.. code-block:: bash
76+
77+
$ python manage.py makemigrations admin auth contenttypes
78+
Migrations for 'admin':
79+
mongo_migrations/admin/0001_initial.py
80+
- Create model LogEntry
81+
...
82+
83+
Creating Django applications
84+
============================
85+
86+
Whenever you run ``python manage.py startapp``, you must remove the line::
87+
88+
default_auto_field = 'django.db.models.BigAutoField'
89+
90+
from the new application's ``apps.py`` file (or change it to reference
91+
``"django_mongodb_backend.fields.ObjectIdAutoField"``).
92+
93+
Alternatively, you can use the following :djadmin:`startapp` template which
94+
includes this change:
95+
96+
.. code-block:: bash
97+
98+
$ python manage.py startapp myapp --template https://github.com/mongodb-labs/django-mongodb-app/archive/refs/heads/5.1.x.zip
99+
100+
(If you're using a version of Django other than 5.1.x, replace the two numbers
101+
to match the first two numbers from your version.)
102+
103+
.. _configuring-databases-setting:
104+
105+
Configuring the ``DATABASES`` setting
106+
=====================================
107+
108+
After you've set up a project, configure Django's :setting:`DATABASES` setting
109+
similar to this::
110+
111+
DATABASES = {
112+
"default": {
113+
"ENGINE": "django_mongodb_backend",
114+
"HOST": "mongodb+srv://cluster0.example.mongodb.net",
115+
"NAME": "my_database",
116+
"USER": "my_user",
117+
"PASSWORD": "my_password",
118+
"PORT": 27017,
119+
"OPTIONS": {
120+
# Example:
121+
"retryWrites": "true",
122+
"w": "majority",
123+
"tls": "false",
124+
},
125+
},
126+
}
127+
128+
For a localhost configuration, you can omit :setting:`HOST` or specify
129+
``"HOST": "localhost"``.
130+
131+
:setting:`HOST` only needs a scheme prefix for SRV connections
132+
(``mongodb+srv://``). A ``mongodb://`` prefix is never required.
133+
134+
:setting:`OPTIONS` is an optional dictionary of parameters that will be passed
135+
to :class:`~pymongo.mongo_client.MongoClient`.
136+
137+
Specify :setting:`USER` and :setting:`PASSWORD` if your database requires
138+
authentication.
139+
140+
:setting:`PORT` is optional if unchanged from MongoDB's default of 27017.
141+
142+
For a replica set or sharded cluster where you have multiple hosts, include
143+
all of them in :setting:`HOST`, e.g.
144+
``"mongodb://mongos0.example.com:27017,mongos1.example.com:27017"``.
145+
146+
Alternatively, if you prefer to simply paste in a MongoDB URI rather than parse
147+
it into the format above, you can use
148+
:func:`~django_mongodb_backend.utils.parse_uri`::
149+
150+
import django_mongodb_backend
151+
152+
MONGODB_URI = "mongodb+srv://my_user:[email protected]/myDatabase?retryWrites=true&w=majority&tls=false"
153+
DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI)
154+
155+
This constructs a :setting:`DATABASES` setting equivalent to the first example.
156+
157+
Congratulations, your project is ready to go!

docs/source/intro/index.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
===============
2+
Getting started
3+
===============
4+
5+
New to Django or MongoDB? Well, you came to the right place: read this material
6+
to quickly get up and running.
7+
8+
.. toctree::
9+
:maxdepth: 1
10+
11+
install
12+
configure
13+
14+
.. seealso::
15+
16+
If you're new to Django_, you might want to start by getting an idea of
17+
what it's like.
18+
19+
For a tutorial that covers using this library with MongoDB Atlas (a fully
20+
managed cloud database service that hosts MongoDB), read
21+
:doc:`mongodb:get-started`.
22+
23+
Another excellent tutorial that covers Django in more detail is the
24+
:doc:`official Django tutorial <django:intro/tutorial01>`.
25+
26+
.. _Django: https://www.djangoproject.org/

docs/source/intro/install.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=================================
2+
Installing Django MongoDB Backend
3+
=================================
4+
5+
Use the version of ``django-mongodb-backend`` that corresponds to your version
6+
of Django. For example, to get the latest compatible release for Django 5.1.x:
7+
8+
.. code-block:: bash
9+
10+
$ pip install --pre django-mongodb-backend==5.1.*
11+
12+
(Until the package is out of beta, you must use pip's ``--pre`` option.)
13+
14+
The minor release number of Django doesn't correspond to the minor release
15+
number of ``django-mongodb-backend``. Use the latest minor release of each.
16+
17+
Next, you'll have to :doc:`configure your project <configure>`.
File renamed without changes.

0 commit comments

Comments
 (0)