Skip to main content

Improve the Sphinx autodoc for Django classes.

Project description

sphinxcontrib-django
====================

Improvements for the output of Sphinx's autodoc for Django classes.

This adds the following improvements:

* Properly show which fields a model has.
* Properly show which fields a form has.
* Document the model fields as parameters in the model ``__init__()``.
* Link foreign key and related fields to the documentation of the referenced class.
* Hide irrelevant runtime information like ``declared_fieldsets``, ``fieldsets`` and ``Meta`` from classes.
* A ``:django:setting:`` role to allow linking to Django documentation. (e.g. *:django:setting:`SITE_ID`*)


Installation
------------

Usage:

.. code-block:: bash

pip install sphinxcontrib-django

Add to the Sphinx config file (:file:`conf.py`):

.. code-block:: python

extensions = [
'sphinx.ext.autodoc',
'sphinxcontrib_django',
]

Autodoc works by importing your code on the fly, and extracting the data from
the Python classes. Thus, the project should be able to import Django models.
Typically the following needs to be added to :file:`conf.py`:

.. code-block:: python

sys.path.insert(0, os.path.abspath('../src'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
django.setup()

To support the ``:django:setting:`` role, configure Intersphinx:

.. code-block:: python

intersphinx_mapping = {
'http://docs.python.org/': None,
'https://docs.djangoproject.com/en/stable': 'https://docs.djangoproject.com/en/stable/_objects',
}


Recommendations:
~~~~~~~~~~~~~~~~

When your project uses Celery, include `celery.contrib.sphinx`_ too.
This adds an ``autotask::`` directive, and ``:task:\`app.tasks.my_task\```*role.

Other great extensions are:

* sphinx-autodoc-annotation_: Converts Python 3 annotations to docstrings.
* ``sphinx.ext.graphviz``: Allows to create diagrams with ease.

An example configuration may look like:

.. code-block:: python

extensions = [
'sphinx.ext.autodoc', # The autodoc core
'sphinx.ext.graphviz', # Support creating charts!

'celery.contrib.sphinx', # Celery improvements!
'sphinx_autodoc_annotation', # Parses Python 3 annotations
'sphinxcontrib_django', # this module
]


.. _sphinx-autodoc-annotation: https://github.com/nicolashainaux/sphinx-autodoc-annotation
.. _celery.contrib.sphinx: http://docs.celeryproject.org/en/latest/reference/celery.contrib.sphinx.html


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinxcontrib-django-0.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

sphinxcontrib_django-0.1-py2.py3-none-any.whl (9.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sphinxcontrib-django-0.1.tar.gz.

File metadata

File hashes

Hashes for sphinxcontrib-django-0.1.tar.gz
Algorithm Hash digest
SHA256 3fb547bd7f2103e40324448893857e9c529067993e4b7655beda768008140496
MD5 a3fdc9e7f88d91720e37a069364f3132
BLAKE2b-256 2e4902bd193a6d82a76c7b48c2516ca79f7e2b0652366cb4a7ddcd1e02e3ee0f

See more details on using hashes here.

File details

Details for the file sphinxcontrib_django-0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for sphinxcontrib_django-0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 68cd6fb6ca5279381dae147278d0f463d75da1bc6df390bdffb1b4128c68db7d
MD5 44076ff73f1ba9feafaf019bd3d7b68c
BLAKE2b-256 04d8cbdc93e1de3128beffc09ee6075ede2620d15904e5df861438bc56e55d55

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page