<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: batchselect</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/batchselect.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2009-11-23T16:19:52+00:00</updated><author><name>Simon Willison</name></author><entry><title>django-batch-select</title><link href="https://simonwillison.net/2009/Nov/23/batchselect/#atom-tag" rel="alternate"/><published>2009-11-23T16:19:52+00:00</published><updated>2009-11-23T16:19:52+00:00</updated><id>https://simonwillison.net/2009/Nov/23/batchselect/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://github.com/lilspikey/django-batch-select"&gt;django-batch-select&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
A smart attempt at solving select_related for many-to-many relationships in Django. Add a custom manager to your model and call e.g. &lt;code&gt;Entry.objects.all()[:10].batch_select("tags")&lt;/code&gt; to execute two queries - one pulling back the first ten entries and another using an "IN" query against the tags table to pull back all of the tags for those entries in one go.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="http://www.psychicorigami.com/2009/11/23/django-batch-select/"&gt;Psychic Origami&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/batchselect"&gt;batchselect&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/django"&gt;django&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/john-montgomery"&gt;john-montgomery&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/manytomany"&gt;manytomany&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/orm"&gt;orm&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/selectrelated"&gt;selectrelated&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/sql"&gt;sql&lt;/a&gt;&lt;/p&gt;



</summary><category term="batchselect"/><category term="django"/><category term="john-montgomery"/><category term="manytomany"/><category term="orm"/><category term="python"/><category term="selectrelated"/><category term="sql"/></entry></feed>