django-tables2 flooding database with queries
<p>im using django-tables2 in order to show values from a database query. And everythings works fine. Im now using Django-dabug-toolbar and was looking through my pages with it. More out of curiosity than performance needs. When a lokked at the page with the table i saw that the debug toolbar registerd over 300 queries for a table with a little over 300 entries. I dont think flooding the DB with so many queries is a good idea even if there is no performance impact (at least not now). All the data should be coming from only one query.</p>

<p>Why is this happening and how can i reduce the number of queries?</p>

<p>Im posting this as a future reference for myself and other who might have the same problem. </p>

<p>After searching for a bit I found out that django-tables2 was sending a single query for each row. The query was something like <code>SELECT * FROM "table"  LIMIT 1 OFFSET 1</code> with increasing offset. </p>

<p>I reduced the number of sql calls by calling <code>query = list(query)</code> before i create the table and pass the query. By evaluating the query in the python view code the table now seems to work with the evaulated data instead and there is only one database call instead of hundreds.</p>

python django django-tables2