Member-only story

How to speed up and optimize your Django admin

Taiwo Kareem
2 min readMay 18, 2022

--

Have you found yourself asking this question “My django admin is really slow. How can I optimise it”? In this article, I will be showing you a useful Django admin feature to help speed up your Django admin and minimise a lot of database queries.

I first found out this very useful django admin property when I was wondering why my Django admin was very slow. I had a model that displayed different related objects in the list display fields as seen in the screenshot below.

It took about 28 seconds and 271 queries to load the Django admin which was quite frustuating but after adding list_select_related, the time reduced significantly.

Note that this is only useful for foreign key relations and one to one fields but not ManyToManyField. If you want to optimise for ManyToManyField, please check out the package named django autoprefetch.

After adding the following, you will see the significant decrease in page load speed as well as in sql queries.

--

--

No responses yet