Django admin edit page massive SQL slowdown with LEFT OUTER JOIN.

I was debugging why a particular page suddenly sent my postgresql process through the roof / eating a gig of memory before I shut it down.

I started debugging the SQL itself, and saw a LEFT OUTER JOIN. I was wondering where this magic was coming from…

It turns out the culprit was obvious: by default, a django admin ForeignKey field will list ALL objects in the referenced table. If that table is very large, it will pull all fields for every object there and consume your server.

Simply set the foreign key field in the readonly_fields to prevent this behavior.

1 Comment

Leave a reply to noorsyron Cancel reply