title: Nested object listing with conditions
body: <p>I'm still new to django and it surprised me that I haven't found satisfying answer, but anyway.</p>
  
  <p>I have following model structure (for ordering food every day):</p>
  
  <pre><code># Extended user profile
  class UserProfile(models.Model)
  # One day - daily menu
  class OrderingDay(models.Model)
  # One menu (there
  class MenuItem(models.Model)
      date = models.ForeignKey(OrderingDay, null=True, blank=True)
  
  # One user ordered something during the day
  class Order(models.Model):
      user = models.ForeignKey(UserProfile)
      date = models.ForeignKey(OrderingDay)
      item = models.ForeignKey(MenuItem)
  </code></pre>
  
  <p>There are some menus that are changed every day (for example <em>Chicken soup</em> is available only on Monday, <code>MenuItem.date = not null</code>) and some meals (<em>Hamburger</em>) that are available every day (<code>MenuItem.date = null</code>).</p>
  
  <p>And I just want to list all orders that currently logged user made:</p>
  
  <pre><code>Monday:
       Hamburger
       Chicken Soup
  
  # Nothing on Tuesday - skip
  
  Wednesday:
      Meatballs 
  </code></pre>
  
  <p>I'm able to filter <code>OrderingDays</code> when user has made an order:</p>
  
  <pre><code>class CurrentOrdersListingView(generic.ListView):
      model = OM.OrderingDay
      context_object_name='ordering_days'
  
      def get_queryset(self):
          return OM.OrderingDay.filter(order__user=self.request.user)\
                 .distinct()
  </code></pre>
  
  <p>But I was unable to google how to list <code>orders</code> (I found about <a href="https://docs.djangoproject.com/en/1.7/topics/db/queries/#following-relationships-backward" rel="nofollow">following relations backwards</a>) with reused filter. </p>
  
  <p>How can I achieve following syntax for template:</p>
  
  <pre><code>{% for od in ordering_days %}
  &lt;h2&gt;{{ od.date }}&lt;/h2&gt;
      {% for item in od.items_by_current_user %}
          {{ item }}
      {% endfor %}
  {% endfor %}
  </code></pre>