title: Django - filtering RelatedManager _set in template?
body: <p>We have a Django DetailView where we're displaying an an object (<code>Site</code>), along with all of it's related objects (<code>Rooms</code>).</p>
  
  <p>Now, in the template, we could simply iterate over the RelatedManager set:</p>
  
  <pre><code>{% for room in site.room_set.all %}
      do stuff
  {% endfor %}
  </code></pre>
  
  <p>However, the problem for this is that this will pick up <em>all</em> related rooms to a site - however, we need to narrow this set down somewhat by another attribute (let's call it <code>year</code>) - and this attribute is stored in a Django session variable.</p>
  
  <p>Currently, we're just using <code>Room.objects.filter(site=some_site, year='2009')</code> in the view code, and that's fine.</p>
  
  <p>My question is more from curiosity - is there any way to use <code>_set</code> in the template, and still filter down or narrow the set?</p>
  
  <p>Could you write a custom Model Manager to do this, so that <code>_set</code> will only ever return objects for the current year? Or is there some other way?</p>
  
  <p>Cheers,
  Victor</p>