views:

456

answers:

2

I have an admin view which contains four foreign keys each with a few thousand entries. It is slow to appear in the browser.

If I change the django model to eliminate the select boxes by adding raw_id_fields things become nice and snappy. So the slowness is due to the population of the select drop downs and also this is a known issue since that is why raw_id_fields exists.

I'd like to understand what is causing the slowness. On the server, if I do a SQL query for the data which are used to populate the select boxes, results are instantaneous. So Postgres retrieving or sorting the data is not the cause.

Maybe it is the time it takes to transfer the data populating the drop downs? Or is it something that django is doing?

+5  A: 

Transferring huge select lists does take quite a bit of time. The markup can really start to add up. Try checking to see how large in KB/MB your html output is. I remember once seeing a select list (a few 1000 entries) bloat a page up to 5 or so megabytes at a previous job. This was on an ASP.NET project; it doesn't really matter what framework you're using when you have a problem like this.

I'm not sure if the django admin tool can do this, but it sounds like you really need a multi-level select list to drill down to results, rather than sending every option to the client at once.

Stuart Branham
It's 600KB, so it looks like that could explain it. Thanks.
Mitch
+1  A: 

1st thing to do is implement gzip on your site this will cut the size of responses at least in half.

Then, if it is still really slow maybe look into some type of ajax auto-suggest type widget to handle selecting the right value. Looks like there is aleady some documented solutions for this: http://www.google.com/#hl=en&q=django+autocomplete+widget&btnG=Google+Search&aq=1&oq=django+autocomplete+widget&fp=jFFhzb_S4-4

NathanD