title: Django: How to get data connected by ForeignKey via Template?
body: <p>Since a few weeks I am learning Python and Django. Up to this point it has been enough to read the questions and the answers of other users.But now the moment of my first own question has come.</p>
  
  <p>I will try to describe my problem as best i can. My problem is that I cant query or get the data I want. </p>
  
  <p>I want to get the url of the first object of class Image which is associated by ForeignKey to a Gallery, which is associated by ForeignKey to the class Entry.</p>
  
  <p>Here the models.py so far:</p>
  
  <pre><code>class BlogEntry(models.Model):
     ...
     title = models.CharField(max_length=100)
     ...
  
  class Gallery(models.Model):
     entry = models.ForeignKey('BlogEntry')
  
  class Image(models.Model):
    gallery = models.ForeignKey('Gallery')
    picture = models.ImageField(upload_to='img')
  </code></pre>
  
  <p>The View:</p>
  
  <pre><code>def view(request):
    return render_to_response('mainview.html', {
      'entryquery': BlogEntry.objects.all(),
      }
  )
  </code></pre>
  
  <p>The Template:</p>
  
  <pre><code>{% for item in entryquery %}
    &lt;h1&gt;{{ item.title }}&lt;/h1&gt;
    &lt;img src="{{ item.WHAT TO ENTER HERE? :) }}" /&gt;
  {% endfor %}
  </code></pre>
  
  <p>It is clear what I want? 
  Could somebody help me and when possible write a short explanation?</p>
  
  <p>greetings
  Bastian</p>