# Diagram of django view lifecycle

**URL:** <https://forum.djangoproject.com/t/diagram-of-django-view-lifecycle/14894>\
**Category:** The Admin\
**Created:** [July 19, 2022, 4:28pm UTC](https://forum.djangoproject.com/t/diagram-of-django-view-lifecycle/14894 "2022-07-19T16:28:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrchrisadams](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/mrchrisadams/32/1904_2.png) [@mrchrisadams](https://forum.djangoproject.com/u/mrchrisadams)\
**Post date:** [July 19, 2022, 4:28pm UTC](https://forum.djangoproject.com/t/diagram-of-django-view-lifecycle/14894/1 "2022-07-19T16:28:36Z")

</div>

Hi folks,

I’m doing a quite a lot of work with django admin views on a project, and I’m wishing I had a diagram to refer to understand how a django admin page is created, in terms of when queries are made for each inline that is show on a page.

Does such a thing exist?

I’m thinking specifically about when get\_queryset(), get\_context\_data() might be called, on the main model form, and then for any inlines, and so on.

I’m happy to have a go, as I’m sure I’ll need to come back to it in future, before I start, does this exist anywhere?

---

<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:** [July 19, 2022, 4:53pm UTC](https://forum.djangoproject.com/t/diagram-of-django-view-lifecycle/14894/3 "2022-07-19T16:53:33Z")

</div>

Sorry, didn’t notice at first that you were talking about the admin views.

I’m not aware of any detailed structural information on them.

---

<div class="post-metadata">

**Author:** ![Eleuthar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eleuthar/32/15916_2.png) [@Eleuthar](https://forum.djangoproject.com/u/Eleuthar)\
**Post date:** [February 15, 2024, 5:45pm UTC](https://forum.djangoproject.com/t/diagram-of-django-view-lifecycle/14894/4 "2024-02-15T17:45:06Z")

</div>

Hey Chris, replying here for other people who land here looking for the same.  
Your best bet would be to print something suggestive within each method of the classes BaseModelAdmin & ModelAdmin, you can find them under site-packages/django/contrib/admin/options.py

This is what I got, but keep in mind that this is the general order, not all methods will be executed for every action in the admin interface.

1. `get_changelist`
2. `get_changelist_form`
3. `get_changelist_formset`
4. `get_form`
5. `get_fieldsets`
6. `get_prepopulated_fields`
7. `get_readonly_fields`
8. `get_queryset`
9. `get_search_results`
10. `get_urls`
11. `get_inline_instances`
12. `get_object`
13. `formfield_for_foreignkey`
14. `formfield_for_manytomany`
15. `formfield_for_choice_field`
16. `formfield_for_dbfield`
17. `save_related`
18. `delete_model`
19. `save_model`
20. `save_formset`
21. `log_addition`
22. `log_change`
23. `log_deletion`

---

<div class="post-metadata">

**Author:** ![aze](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aze/32/19166_2.png) [@aze](https://forum.djangoproject.com/u/aze)\
**Post date:** [February 16, 2024, 2:55pm UTC](https://forum.djangoproject.com/t/diagram-of-django-view-lifecycle/14894/5 "2024-02-16T14:55:21Z")

</div>

Hello @Eleuthar , can you please give some example how you would go about printing and seeing the order?

I have to work with the Django admin these days and I really want to understand it better 🙂

---

<div class="post-metadata">

**Author:** ![Eleuthar](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/eleuthar/32/15916_2.png) [@Eleuthar](https://forum.djangoproject.com/u/Eleuthar)\
**Post date:** [February 17, 2024, 6:46am UTC](https://forum.djangoproject.com/t/diagram-of-django-view-lifecycle/14894/6 "2024-02-17T06:46:39Z")

</div>

Create a virtual environment with venv and go to the options.py file in the above mentioned path.  
At the beginning of each method, type the print statement.
