# I'm looking for a class hierarchy diagram of classes used by Django

**URL:** <https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343>\
**Category:** Getting Started\
**Created:** [March 7, 2025, 3:28am UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343 "2025-03-07T03:28:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![shearichard](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shearichard/32/16569_2.png) [@shearichard](https://forum.djangoproject.com/u/shearichard)\
**Post date:** [March 7, 2025, 3:28am UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343/1 "2025-03-07T03:28:21Z")

</div>

I’d like a class hierarchy diagram for the core Django modules (conf; contrib; core; db; dispatch; forms; http; middleware; template; templatetags; test; urls; utils; and views). I feel like I’ve seen this before but I can’t now find it in the Django documentation, or anywhere else come to that.

Alternatively if anyone has a recipe for using, say, pyreverse to produce this diagram would you share it please ? I have tried using pyreverse and the django\_extensions graph\_models but I can’t work out how to point it at, for instance, django.db.models.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 7, 2025, 4:12am UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343/2 "2025-03-07T04:12:45Z")

</div>

> [@shearichard](#):
>
> I feel like I’ve seen this before but I can’t now find it in the Django documentation

I don’t remember ever seeing anything like that in the django docs.

> [@shearichard](#):
>
> Alternatively if anyone has a recipe for using, say, pyreverse to produce this diagram would you share it please ?

I don’t know about a recipe, but I just did a little playing around with pyreverse and managed to get diagrams of `django.db.models` by running `pyreverse django.db.models`. That generates a pair of `.dot` files (`classes.dot` and `packages.dot` by default) that can then be converted to a variety of graphic image formats using `graphviz`.

(Interesting to see, but I find the resultant graph created by `dot` to be too big to be of any use.)

If you’re having a specific issue getting this to work, then it might be helpful if you provided the details of what you’re trying and what the results are that you are getting.

---

<div class="post-metadata">

**Author:** ![shearichard](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shearichard/32/16569_2.png) [@shearichard](https://forum.djangoproject.com/u/shearichard)\
**Post date:** [March 7, 2025, 4:45am UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343/3 "2025-03-07T04:45:28Z")

</div>

Thank you. That does work for me. Looking back though my shell history the nearest I got was `pyreverse db.models` , not sure why I thought that was going to cut it but it seemed reasonable at the time.

Having now seen the output I agree the output (at least of django.db.models) is too large to be useful to comprehend. I will try it with some of the other top level packages, but perhaps reconsider whether there are better options.

Thanks for your help, I appreciate it.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 7, 2025, 1:11pm UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343/4 "2025-03-07T13:11:49Z")

</div>

Doing some more playing -

Being more focused on specific classes can help create diagrams that are more useful than just trying to render an entire module.

For example: `pyreverse -c django.forms.models.ModelForm django` produces a much more readable diagram. (Side note: I also prefer using the `-Gsplines=ortho` parameter on the `dot` command. I think it creates a much “neater” image.)

---

<div class="post-metadata">

**Author:** ![shearichard](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shearichard/32/16569_2.png) [@shearichard](https://forum.djangoproject.com/u/shearichard)\
**Post date:** [March 8, 2025, 3:43am UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343/5 "2025-03-08T03:43:13Z")

</div>

> [@KenWhitesell](#):
>
> pyreverse -c django.forms.models.ModelForm django

Thanks, that is certainly more readable both because of the specific classes and the use of the Gsplines option.

I also found using --only-classnames works better than me (although of course many people would want more information).

I also experimented with [–max-depth](https://pylint.readthedocs.io/en/latest/additional_tools/pyreverse/configuration.html#max-depth) but got an error when I did. If anyone has any ideas about that I’d be interested to hear.

One odd thing I don’t understand it that I’m getting some green text which is not associated with any of the classes (see below), needs investigation.

Thanks again for your help.

 ![classes-HOLD](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/4/c/4c30259b95e5158477c110f2a53a9dd72dbb2e71.png)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 8, 2025, 4:07am UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343/6 "2025-03-08T04:07:50Z")

</div>

Briefly, the green label is the name of the variable in the target class containing the type of object pointing to it.

For example, in this diagram, the green label “iterator” near the center is identifying that the variable “iterator” in `ModelChoiceField` is an instance of `ModelChoiceIterator`.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 8, 2025, 7:43pm UTC](https://forum.djangoproject.com/t/im-looking-for-a-class-hierarchy-diagram-of-classes-used-by-django/39343/7 "2025-03-08T19:43:49Z")

</div>

> [@shearichard](#):
>
> I also experimented with [–max-depth](https://pylint.readthedocs.io/en/latest/additional_tools/pyreverse/configuration.html#max-depth) but got an error when I did. If anyone has any ideas about that I’d be interested to hear.

From what I can tell, the version of `pylint` on `pypi` doesn’t have a `max-depth` parameter. The docs you’re referencing are for version `4.0.0`, while the version on `pypi` is `3.3.4`.

See [Add --max-depth option to control diagram complexity by Julfried · Pull Request #10077 · pylint-dev/pylint · GitHub](https://github.com/pylint-dev/pylint/pull/10077)

You’d have to install the version from github to have that feature available.
