title: Django reverse lookup chaining queryset
body: <p>I have several models that I need to do reverse lookups in, then somehow chain the querysets together. </p>
  
  <p>I got 3 models, (1) designers create (2) projects, and projects contain (3) uploaded images. </p>
  
  <p><strong>Models</strong></p>
  
  <pre><code>class Designer(models.Model):
      ... 
  
  class Project(models.Model):
      designer = models.ForeignKey('Designer')
  
  class UploadedImage(models.Model):
      project = models.ForeignKey('Project')
  </code></pre>
  
  <p>So a designer opens up his page and wants to see all his projects and some images associated with his projects, I could do something like, </p>
  
  <pre><code>d = Designer.objects.get(id=2)
  projects = d.project_set.all()
  </code></pre>
  
  <p>But then with images, I gotta do this thing many many times, each time hitting the database. </p>
  
  <pre><code>images = []
  for p in projects:
      images.append(p.uploadedimage_set.all())
  </code></pre>
  
  <p>Now we have another problem, which is how do I connect <code>images</code> and <code>projects</code>?? I could do something stupid by building up a dictionary like this, </p>
  
  <pre><code>images = []
  for p in projects:
      images.append( { p.id : p.uploadedimage_set.all() } )
  </code></pre>
  
  <p>Then when I iterate through <code>projects</code>, I could just use the <code>id</code> to figure out which images are associated with which project. </p>
  
  <p>Isn't there something a lot more elegant that'll allow me to, </p>
  
  <ol>
  <li>Hit the database just once</li>
  <li>Allow me to do something that'll look like <code>d.projects[0].images[0]</code>??? Instead of building up some sort of a stupid custom dictionary??? Does Django have some sort of queryset building tool or whatever? </li>
  </ol>
  
  <p>Thanks!! </p>