We have a Django DetailView where we show an object ( Site ) along with all related objects ( Rooms ).
Now, in the template, we can simply iterate over the RelatedManager set:
{% for room in site.room_set.all %} do stuff {% endfor %}
However, the problem is that this will result in all related rooms being hosted on the site. However, we need to narrow this set down with a slightly different attribute (let it be called year ) - and this attribute is stored in a Django session variable.
Currently, we just use Room.objects.filter(site=some_site, year='2009') in the view code, which is great.
My question is more out of curiosity - is there a way to use _set in a template and still filter or narrow the set?
Could you write your own model manager for this, so that _set returns objects only for the current year? Or is there some other way?
Cheers, Victor
source share