Skip to main content

django-model-info

PyPI Python versions Django versions Documentation License: MIT

Instantly understand your Django models' structure and relationships with beautiful, intuitive output.

Working with complex Django projects? Need to quickly understand model relationships and fields? django-model-info is an ideal solution for diving into any Django codebase with confidence.

Why django-model-info?

Four django management commands provide detailed information about your models, relationships, and migrations:

  • Perfect for New Team Members: Quickly understand existing codebases without diving through multiple files.
  • Great for Documentation: Export beautiful HTML or Markdown documentation of your models' structure and relationships.
  • Ideal for Large Projects: Filter by app or model to focus on what matters.
  • Time-Saving: Instantly see model-related information without writing custom scripts.
  • Useful Output: Leverages tools like rich, Markdown, MermaidJS, and Graphviz for beautiful output.

Quick Start

  1. Install the package:
pip install django-model-info
  1. Add to INSTALLED_APPS:
INSTALLED_APPS = (
    ...
    'django_model_info.apps.DjangoModelInfoConfig',
    ...
)

You now have access to four new management commands:

  • modelinfo: Display detailed information about your models
  • modelgraph: Generate a graph of your models and their relationships
  • modelfilters: Understand how to filter queries for complex Django model relationships
  • migrationgraph: Visualize and understand the dependencies between migrations

Example Outputs

modelinfo

HTML Output

python manage.py modelinfo sales -v 3 -o modelinfo.html

Rendered, Raw

Markdown Output

python manage.py modelinfo sales -v 3 -o modelinfo.md

Rendered, Raw

modelfilters

HTML Output

python manage.py modelfilters sales --target-model Customer ShippingAddress --target-field-type CharField -o modelfilters.html

Rendered, Raw

Markdown Output

python manage.py modelfilters sales --target-model Customer ShippingAddress --target-field-type CharField -o modelfilters.md

Rendered, Raw

modelgraph

Analysis Output

python manage.py modelgraph

Output:

Model Graph Analysis
===================

Basic Statistics:
  Models: 5
  Relationships: 4

Isolated Models:
  - sales.bankaccount
  - sales.creditcard

Model Relationships:

  sales.order:
    ← sales.orderitem
      ManyToOneRel (reverse: items)
    → sales.shippingaddress
      ForeignKey (shipping_address)

  sales.orderitem:
    → sales.order
      ForeignKey (order)

  sales.shippingaddress:
    ← sales.order
      ManyToOneRel (reverse: order)

MermaidJS Output

python manage.py modelgraph sales -f mermaid

Result:

```mermaid
graph LR
    common_customer-. "ManyToOneRel<br>reverse: sales_creditcards" .->sales_creditcard
    common_customer["common.customer"]
    sales_creditcard["sales.creditcard"]
    common_customer-. "ManyToOneRel<br>reverse: sales_bankaccounts" .->sales_bankaccount
    common_customer["common.customer"]
    sales_bankaccount["sales.bankaccount"]
    common_customer-. "ManyToOneRel<br>reverse: shipping_addresses" .->sales_shippingaddress
    common_customer["common.customer"]
    sales_shippingaddress["sales.shippingaddress"]
    common_customer-. "ManyToOneRel<br>reverse: orders" .->sales_order
    common_customer["common.customer"]
    sales_order["sales.order"]
    sales_bankaccount== "ForeignKey<br>customer" ===common_customer
    sales_bankaccount["sales.bankaccount"]
    common_customer["common.customer"]
    sales_creditcard== "ForeignKey<br>customer" ===common_customer
    sales_creditcard["sales.creditcard"]
    common_customer["common.customer"]
    sales_order-. "ManyToOneRel<br>reverse: items" .->sales_orderitem
    sales_order["sales.order"]
    sales_orderitem["sales.orderitem"]
    sales_order== "ForeignKey<br>customer" ===common_customer
    sales_order["sales.order"]
    common_customer["common.customer"]
    sales_order== "ForeignKey<br>shipping_address" ===sales_shippingaddress
    sales_order["sales.order"]
    sales_shippingaddress["sales.shippingaddress"]
    sales_orderitem== "ForeignKey<br>order" ===sales_order
    sales_orderitem["sales.orderitem"]
    sales_order["sales.order"]
    sales_shippingaddress-. "ManyToOneRel<br>reverse: order" .->sales_order
    sales_shippingaddress["sales.shippingaddress"]
    sales_order["sales.order"]
    sales_shippingaddress== "ForeignKey<br>customer" ===common_customer
    sales_shippingaddress["sales.shippingaddress"]
    common_customer["common.customer"]
```

Dot Output

python manage.py modelgraph -f dot -o modelgraph.dot

Dot File

Rendered

migrationgraph

python manage.py migrationgraph common sales inventory admin

Output:

[common]
common/0001_initial
	Depends on:
		auth/0001_initial
	Depended upon by:
		sales/0001_initial

[sales]
sales/0001_initial
	Depends on:
		common/0001_initial
		inventory/0001_initial

[inventory]
inventory/0001_initial
	Depended upon by:
		sales/0001_initial

[admin]
admin/0001_initial
	Depends on:
		auth/0001_initial
		contenttypes/0001_initial
	Depended upon by:
		admin/0002_logentry_remove_auto_add
admin/0002_logentry_remove_auto_add
	Depended upon by:
		admin/0003_logentry_add_action_flag_choices
admin/0003_logentry_add_action_flag_choices

_____________________
Migrations Flowchart:

```mermaid
graph TD
    sales_0001_initial["sales/0001"]
    inventory_0001_initial["inventory/0001"]
    auth_0001_initial["auth/0001"]
    contenttypes_0001_initial["contenttypes/0001"]
    common_0001_initial["common/0001"]
    admin_0001_initial["admin/0001"]
    admin_0002_logentry_remove_auto_add["admin/0002"]
    admin_0003_logentry_add_action_flag_choices["admin/0003"]
    admin_0001_initial --> admin_0002_logentry_remove_auto_add
    admin_0002_logentry_remove_auto_add --> admin_0003_logentry_add_action_flag_choices
    inventory_0001_initial --> sales_0001_initial
    auth_0001_initial --> admin_0001_initial
    common_0001_initial --> sales_0001_initial
    contenttypes_0001_initial --> admin_0001_initial
    auth_0001_initial --> common_0001_initial
```

Documentation

For detailed usage and examples, visit our full documentation.

Roadmap

  • List manager and queryset methods
  • Include signals and other model-level methods
  • Add MermaidJS support for visualizing relationships

Contributing

We welcome contributions! This project uses:

Background and Credits

The modelinfo command has been something I have slowly been working on and improving for several years. The original idea behind modelfilters came from observing the underlying functionality in the django-drip-campaigns package and realizing that having a way to list potential filter paths could help developers with building complex queries, though my implementation of those ideas is quite different. The modelgraph command was loosely inspired by existing tools like the graph_models command in django-extensions, but I wanted to provide a more detailed, filterable, and customizable output. The migrationgraph command was inspired by recent discussions I read online about migration graphs and dependencies, but I cannot recall the specific thread/post that sparked the idea.

License

MIT License

Metadata

Release files for django-model-info 2026.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-model-info 2026.3.1
File Size Uploaded
django_model_info-2026.3.1.tar.gz 65.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-model-info 2026.3.1
File Interpreter ABI Platform
django_model_info-2026.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 117.5 kB

Release files / django_model_info-2026.3.1.tar.gz

Download URL django_model_info-2026.3.1.tar.gz
Size 65.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4ceceb4766e56f7ec01b75d0ff1458eef14211fff819d3e1396d25ad55e7e323
BLAKE2b-256 checksum
How to use checksums
ac0b5646cc9918636ae6caeba516238ee506c8898e23f7e15ad89072ea2b7d86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / django_model_info-2026.3.1-py3-none-any.whl

Download URL django_model_info-2026.3.1-py3-none-any.whl
Size 51.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cd5043a999b30841f7e2ba64f1ec6e973a080e6c8f0ac8e7a3759131ff2a287
BLAKE2b-256 checksum
How to use checksums
0a6de7b4512da715b344bf9f23f5cc1bb064c56eeecf19608d0adfd965841c81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

2026.3.1 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page