---
title: "Discussion on \"Reducing queries for ForeignKeys in Django admin inlines\" | Hashnode"
description: "Discussion on \"Reducing queries for ForeignKeys in Django admin inlines\". Use 93x less queries using patched raw_id_fields and prefetching"
url: "https://hashnode.com/posts/reducing-queries-for-foreignkeys-in-django-admin-inlines/63becbe911c7835807fb28cb"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Reducing queries for ForeignKeys in Django admin inlines](https://deepintodjango.com/reducing-queries-for-foreignkeys-in-django-admin-inlines?utm_source=hashnode&utm_medium=feed)

Use 93x less queries using patched raw\_id\_fields and prefetching

Jan 11, 2023 · 3 min read · deepintodjango.com  
Updated Apr 24, 2023  
Read the article

-   [#django](https://hashnode.com/tag/django)
-   [#prefetching](https://hashnode.com/tag/prefetching)
-   [#optimization](https://hashnode.com/tag/optimization)
-   [#performance](https://hashnode.com/tag/performance)
-   [#python](https://hashnode.com/tag/python)

## Written by

[Jurrian Tromp](https://hashnode.com/@jurrian)

@jurrian · Utrecht, The Netherlands

  
[View profile](https://hashnode.com/@jurrian)

Freelance Webdeveloper

Made my first website in Microsoft Word at age 13, when I discovered the "save as html" button. Since then I've journeyed various computing languages, eventually settling for Python. I love diving into the core of my favorite framework - Django - discover and writing about new stuff.

## Responses 1

Markdown supported · ⌘↵ to post

[Ander](https://hashnode.com/@AnderUstarroz)

[Aug 4, 2023](https://hashnode.com/posts/reducing-queries-for-foreignkeys-in-django-admin-inlines/63becbe911c7835807fb28cb/comment/64cc4f4a8c8620c6865545fc)

I am having performance issues because of the inlines, I am really curious about your solution, but is it just for Django v4? that way of defining inlines = \["some-inline"\] as strings doesn't look familiar, shouldn't that be classes instead?

[Jurrian Tromp](https://hashnode.com/@jurrian)

[Aug 19, 2023](https://hashnode.com/posts/reducing-queries-for-foreignkeys-in-django-admin-inlines/63becbe911c7835807fb28cb/comment/64cc4f4a8c8620c6865545fc#reply-64e06a78fe582aa061c3f8bd)

AFAIK this is applies to all Django versions. You are right that they should be classes instead. It might be that as a string it still works as lazy loading, so probably both work. The key of the problem is how the Django internals work in such a way that it creates a lot of extra queries.
