title: Django - filtering related objects in "backward" relationships
body: <p>I've been working on some models with "backward" relationships. I started wondering... What if I want to filter some results?</p>
  
  <p>I've got two models:</p>
  
  <pre><code>Model A:
   name
   image
   date 
  
  Model B:
   ForeignKey to Model A
   name
   date
  </code></pre>
  
  <p>To access model A I use:
      p = A.objects.all().order_by('-date')</p>
  
  <p>and I pass that to template.</p>
  
  <p>In template:</p>
  
  <pre><code>{% for n in model_a.all %}
    {% for item in n.modelb_set.all %}
  
     &lt;li&gt;{{item.name}}&lt;/li&gt;
  
    {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>I get all backward related objects for model A and thats fine.</p>
  
  <p>Now what if I want to filter some results from that query?</p>
  
  <p>I was thinking of iteration in a View by:</p>
  
  <pre><code>p = A.objects.all().order_by('-date')
  
  for n in p:
      for x in n.modelb_set.filter(date_lte=""):
      ls = []
      ls.append[x]
  </code></pre>
  
  <p>How do I pass that to the template and get what I got earlier (unfiltered view) but now with filtered results?</p>