<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: manytomany</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/manytomany.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><entry><title>Extra fields on many-to-many relationships</title><link href="https://simonwillison.net/2008/Jul/29/extra/#atom-tag" rel="alternate"/><published>2008-07-29T13:58:45+00:00</published><updated>2008-07-29T13:58:45+00:00</updated><id>https://simonwillison.net/2008/Jul/29/extra/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://www.djangoproject.com/documentation/model-api/#extra-fields-on-many-to-many-relationships"&gt;Extra fields on many-to-many relationships&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Checked in just over an hour ago, Django now lets you specify a custom “through” table for a ManyToManyField. Great work by Eric Florenzano.

    &lt;p&gt;&lt;small&gt;&lt;/small&gt;Via &lt;a href="http://code.djangoproject.com/changeset/8136"&gt;Changeset 8136&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/django"&gt;django&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/eric-florenzano"&gt;eric-florenzano&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/manytomany"&gt;manytomany&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/through"&gt;through&lt;/a&gt;&lt;/p&gt;



</summary><category term="django"/><category term="eric-florenzano"/><category term="manytomany"/><category term="python"/><category term="through"/></entry></feed>