Skip to main content

Improve the Sphinx autodoc for Django classes.

Project description

GitHub Workflow Status PyPi Code coverage Black Code Style GitHub license

sphinxcontrib-django2

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

This is a fork of sphinxcontrib-django, which seems to be no longer maintained. In comparison to the upstream repository, this provides the following:

  • Support for current versions of Python and Django

  • Support for ModelForms

  • Support Intersphinx mappings to Django classes

  • 100% test coverage

The original repository already implemented the following features:

  • 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:

pip install sphinxcontrib-django2

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

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

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 conf.py:

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:

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

Contributing

Pull requests are always welcome!

You can install all requirements of the development setup with Pipenv:

pipenv install --dev
pipenv run pre-commit install

Then, run the tests with:

pipenv run coverage run runtests.py

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-django2-0.7.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

sphinxcontrib_django2-0.7-py2.py3-none-any.whl (16.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file sphinxcontrib-django2-0.7.tar.gz.

File metadata

  • Download URL: sphinxcontrib-django2-0.7.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6

File hashes

Hashes for sphinxcontrib-django2-0.7.tar.gz
Algorithm Hash digest
SHA256 4c673da1edef6e8605f15177df7ae9ef61a2e54b4f8065f665a2a83005df9708
MD5 9fb9a0152582b1223cfaa85855533135
BLAKE2b-256 25003b9b63d81a74f856cce9d802b4f290ffca3edcf4e847ff8bc657f4ca0e67

See more details on using hashes here.

File details

Details for the file sphinxcontrib_django2-0.7-py2.py3-none-any.whl.

File metadata

  • Download URL: sphinxcontrib_django2-0.7-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.8.6

File hashes

Hashes for sphinxcontrib_django2-0.7-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3d4688a49fc7a526675a213b763e21210400c60d520425b23256353d0c9842f7
MD5 90fa639094bfe186f4bbc3be8c2f572b
BLAKE2b-256 4b85e5add21832ca2582def0fc79c06dc1a60ace0f39438984b4a0b82ad069d0

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