Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The ORM does not need to track the rows fetched, instead it identifies rows by their primary key to determine, whether to insert or to update (if you don't set force_insert or force_update with save()).</p> <p>Who can read about this here: <a href="http://docs.djangoproject.com/en/1.2/ref/models/instances/#how-django-knows-to-update-vs-insert" rel="nofollow noreferrer">http://docs.djangoproject.com/en/1.2/ref/models/instances/#how-django-knows-to-update-vs-insert</a></p> <p>This said, it is not necessary or even possible to use a model "read only" since it wouldn't yield any performance improvement.</p> <p>If you want to optimize, there are however some steps you can try (however only small improvements, so you probably should not optimze until it is really necessary).</p> <p>For example, call <code>querySet.exists()</code> resp. <code>querySet.count()</code> instead of <code>(bool)querySet</code> resp. <code>len(querySet)</code> if (and only if) you are not reading from the query set afterwards. Otherwise, don't use exists()/count(), since it will produce an additional query whereas in the latter cache, the actual reading of the query set is free of cost since it is already cached then.</p> <p>Another measure is to use only() and defer() to restrict the SELECT to the fields that you actually need and select_related() to pre-fetch foreign key relations, if you know you will need them. If you have larger models with many relations and columns, this can give you a significant performance boost.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload