# Django admin inline causes timeout when there are large amount of inline data

**URL:** <https://forum.djangoproject.com/t/django-admin-inline-causes-timeout-when-there-are-large-amount-of-inline-data/6675>\
**Category:** Using Django\
**Created:** [February 19, 2021, 6:10pm UTC](https://forum.djangoproject.com/t/django-admin-inline-causes-timeout-when-there-are-large-amount-of-inline-data/6675 "2021-02-19T18:10:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devspectre](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devspectre/32/3559_2.png) [@devspectre](https://forum.djangoproject.com/u/devspectre)\
**Post date:** [February 19, 2021, 6:10pm UTC](https://forum.djangoproject.com/t/django-admin-inline-causes-timeout-when-there-are-large-amount-of-inline-data/6675/1 "2021-02-19T18:10:43Z")

</div>

I have a model and there are thousands of its instances.  
On django admin, if I select one instance which has the largest amount of inlines(two inlines and there are hundreds of objects for each inline fields), the admin does not respond and times out finally.  
For other instances, it does not happen because all the other instances have very less inline objects assocaited.  
How can I resolve this problem?  
Should I remove inlines from admin?

Please help me!

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [February 19, 2021, 6:33pm UTC](https://forum.djangoproject.com/t/django-admin-inline-causes-timeout-when-there-are-large-amount-of-inline-data/6675/2 "2021-02-19T18:33:51Z")

</div>

I’d install the [debug toolbar](https://django-debug-toolbar.readthedocs.io/en/latest/) to help debug the N+1 queries you’re likely encountering as well as verify your performance optimization changes.

One way to improve performance without much effort, though at the expense of functionality is to use [`raw_id_fields`](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.raw_id_fields).

Another way to improve performance is to override the form class with to apply filters on the field’s queryset. This assumes that filtering is even applicable for your project’s domain.

---

<div class="post-metadata">

**Author:** ![devspectre](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/devspectre/32/3559_2.png) [@devspectre](https://forum.djangoproject.com/u/devspectre)\
**Post date:** [February 19, 2021, 6:46pm UTC](https://forum.djangoproject.com/t/django-admin-inline-causes-timeout-when-there-are-large-amount-of-inline-data/6675/3 "2021-02-19T18:46:11Z")

</div>

Thanks  
I am trying to create a link to show inlines in a separate page.  
And yes, I have autocomplete\_field for those inlines and I think raw\_id\_fields might help.

Thank you. I will let you know once I resolve this.

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [February 19, 2021, 10:27pm UTC](https://forum.djangoproject.com/t/django-admin-inline-causes-timeout-when-there-are-large-amount-of-inline-data/6675/4 "2021-02-19T22:27:09Z")

</div>

Give the debug toolbar a try. It can help you identify some easy fixes via `select_related` and `prefetch_related`.
