Skip to content

Commit d7a1118

Browse files
committed
restructure docs per Diátaxis framework
Add intro, reference, and topic sections
1 parent 2313ae9 commit d7a1118

20 files changed

+510
-218
lines changed

README.md

Lines changed: 2 additions & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -4,176 +4,8 @@ This backend is currently in development and is not advised for Production workf
44
changes may be made without notice. We welcome your feedback as we continue to
55
explore and build. The best way to share this is via our [MongoDB Community Forum](https://www.mongodb.com/community/forums/tag/python)
66

7-
## Install and usage
8-
9-
The development version of this package supports Django 5.0.x. To install it:
10-
11-
`pip install git+https://github.com/mongodb-labs/django-mongodb-backend`
12-
13-
### Specifying the default primary key field
14-
15-
In your Django settings, you must specify that all models should use
16-
`ObjectIdAutoField`.
17-
18-
You can create a new project that's configured based on these steps using a
19-
project template:
20-
21-
```bash
22-
$ django-admin startproject mysite --template https://github.com/mongodb-labs/django-mongodb-project/archive/refs/heads/5.0.x.zip
23-
```
24-
(where "5.0" matches the version of Django that you're using.)
25-
26-
This template includes the following line in `settings.py`:
27-
28-
```python
29-
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField"
30-
```
31-
32-
But this setting won't override any apps that have an `AppConfig` that
33-
specifies `default_auto_field`. For those apps, you'll need to create a custom
34-
`AppConfig`.
35-
36-
For example, the project template includes `<project_name>/apps.py`:
37-
38-
```python
39-
from django.contrib.admin.apps import AdminConfig
40-
from django.contrib.auth.apps import AuthConfig
41-
from django.contrib.contenttypes.apps import ContentTypesConfig
42-
43-
44-
class MongoAdminConfig(AdminConfig):
45-
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
46-
47-
48-
class MongoAuthConfig(AuthConfig):
49-
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
50-
51-
52-
class MongoContentTypesConfig(ContentTypesConfig):
53-
default_auto_field = "django_mongodb_backend.fields.ObjectIdAutoField"
54-
```
55-
56-
Each app reference in the `INSTALLED_APPS` setting must point to the
57-
corresponding ``AppConfig``. For example, instead of `'django.contrib.admin'`,
58-
the template uses `'<project_name>.apps.MongoAdminConfig'`.
59-
60-
### Configuring migrations
61-
62-
Because all models must use `ObjectIdAutoField`, each third-party and contrib app
63-
you use needs to have its own migrations specific to MongoDB.
64-
65-
For example, `settings.py` in the project template specifies:
66-
67-
```python
68-
MIGRATION_MODULES = {
69-
"admin": "mongo_migrations.admin",
70-
"auth": "mongo_migrations.auth",
71-
"contenttypes": "mongo_migrations.contenttypes",
72-
}
73-
```
74-
75-
The project template includes these migrations, but you can generate them if
76-
you're setting things up manually or if you need to create migrations for
77-
third-party apps. For example:
78-
79-
```console
80-
$ python manage.py makemigrations admin auth contenttypes
81-
Migrations for 'admin':
82-
mongo_migrations/admin/0001_initial.py
83-
- Create model LogEntry
84-
...
85-
```
86-
87-
### Creating Django applications
88-
89-
Whenever you run `python manage.py startapp`, you must remove the line:
90-
91-
`default_auto_field = 'django.db.models.BigAutoField'`
92-
93-
from the new application's `apps.py` file (or change it to reference
94-
`"django_mongodb_backend.fields.ObjectIdAutoField"`).
95-
96-
Alternatively, you can use the following `startapp` template which includes
97-
this change:
98-
99-
```bash
100-
$ python manage.py startapp myapp --template https://github.com/mongodb-labs/django-mongodb-app/archive/refs/heads/5.0.x.zip
101-
```
102-
(where "5.0" matches the version of Django that you're using.)
103-
104-
### Configuring the `DATABASES` setting
105-
106-
After you've set up a project, configure Django's `DATABASES` setting similar
107-
to this:
108-
109-
```python
110-
DATABASES = {
111-
"default": {
112-
"ENGINE": "django_mongodb_backend",
113-
"HOST": "mongodb+srv://cluster0.example.mongodb.net",
114-
"NAME": "my_database",
115-
"USER": "my_user",
116-
"PASSWORD": "my_password",
117-
"PORT": 27017,
118-
"OPTIONS": {
119-
# Example:
120-
"retryWrites": "true",
121-
"w": "majority",
122-
"tls": "false",
123-
},
124-
},
125-
}
126-
```
127-
128-
For a localhost configuration, you can omit `HOST` or specify
129-
`"HOST": "localhost"`.
130-
131-
`HOST` only needs a scheme prefix for SRV connections (`mongodb+srv://`). A
132-
`mongodb://` prefix is never required.
133-
134-
`OPTIONS` is an optional dictionary of parameters that will be passed to
135-
[`MongoClient`](https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html).
136-
137-
`USER`, `PASSWORD`, and `PORT` (if 27017) may also be optional.
138-
139-
For a replica set or sharded cluster where you have multiple hosts, include
140-
all of them in `HOST`, e.g.
141-
`"mongodb://mongos0.example.com:27017,mongos1.example.com:27017"`.
142-
143-
Alternatively, if you prefer to simply paste in a MongoDB URI rather than parse
144-
it into the format above, you can use:
145-
146-
```python
147-
import django_mongodb_backend
148-
149-
MONGODB_URI = "mongodb+srv://my_user:[email protected]/myDatabase?retryWrites=true&w=majority&tls=false"
150-
DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI)
151-
```
152-
153-
This constructs a `DATABASES` setting equivalent to the first example.
154-
155-
#### `django_mongodb_backend.parse_uri(uri, conn_max_age=0, test=None)`
156-
157-
`parse_uri()` provides a few options to customize the resulting `DATABASES`
158-
setting, but for maximum flexibility, construct `DATABASES` manually as
159-
described above.
160-
161-
- Use `conn_max_age` to configure [persistent database connections](
162-
https://docs.djangoproject.com/en/stable/ref/databases/#persistent-database-connections).
163-
- Use `test` to provide a dictionary of [settings for test databases](
164-
https://docs.djangoproject.com/en/stable/ref/settings/#test).
165-
166-
Congratulations, your project is ready to go!
167-
168-
## Notes on Django QuerySets
169-
170-
* `QuerySet.explain()` supports the [`comment` and `verbosity` options](
171-
https://www.mongodb.com/docs/manual/reference/command/explain/#command-fields).
172-
173-
Example: `QuerySet.explain(comment="...", verbosity="...")`
174-
175-
Valid values for `verbosity` are `"queryPlanner"` (default),
176-
`"executionStats"`, and `"allPlansExecution"`.
7+
The documentation in the "docs" directory is online at
8+
https://django-mongodb-backend.readthedocs.io/en/latest/.
1779

17810
## Known issues and limitations
17911

@@ -220,31 +52,3 @@ Congratulations, your project is ready to go!
22052

22153
- Due to the lack of ability to introspect MongoDB collection schema,
22254
`migrate --fake-initial` isn't supported.
223-
224-
## Troubleshooting
225-
226-
### Debug logging
227-
228-
To troubleshoot MongoDB connectivity issues, you can enable [PyMongo's logging](
229-
https://pymongo.readthedocs.io/en/stable/examples/logging.html) using
230-
[Django's `LOGGING` setting](https://docs.djangoproject.com/en/stable/topics/logging/).
231-
232-
This is a minimal `LOGGING` setting that enables PyMongo's `DEBUG` logging:
233-
234-
```python
235-
LOGGING = {
236-
"version": 1,
237-
"disable_existing_loggers": False,
238-
"handlers": {
239-
"console": {
240-
"class": "logging.StreamHandler",
241-
},
242-
},
243-
"loggers": {
244-
"pymongo": {
245-
"handlers": ["console"],
246-
"level": "DEBUG",
247-
},
248-
},
249-
}
250-
```

docs/source/conf.py

Lines changed: 4 additions & 2 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

@@ -45,6 +45,8 @@
4545
"python": ("https://docs.python.org/3/", None),
4646
}
4747

48+
root_doc = "contents"
49+
4850
# -- Options for HTML output -------------------------------------------------
4951
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
5052

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+
faq
16+
ref/index
17+
internals
18+
19+
Indices and tables
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.0.x documentation
2-
==========================================
1+
======================
2+
Django MongoDB Backend
3+
======================
34

4-
.. toctree::
5-
:maxdepth: 1
6-
:caption: Contents:
5+
version 5.0.x for Django 5.0.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.

0 commit comments

Comments
 (0)