Diagram of django view lifecycle

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?

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.

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
2 Likes

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

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.