title: GAE: Efficiently querying entities and their referenced entities
body: <p>I am trying to efficiently return a list of entities, and their respective referenced entities in a template view. For example</p>
  
  <p>We are working with two Kinds: </p>
  
  <pre><code>class Event(ndb.Model):
      """An fun activity or event"""
      name = ndb.StringProperty()
      venue = ndb.KeyProperty()
  
  class Venue(ndb.Model):
      """The venue of an event"""
      name = ndb.StringProperty()
      address = StringProperty()
  </code></pre>
  
  <p>The <code>Event</code> kind references <code>Venue</code> via an <code>ndb.KeyProperty()</code>. To display a list of events and their respective venues into a template, I can first do this query:</p>
  
  <pre><code># we can fetch this from memcache
  events = Event.query().fetch()
  </code></pre>
  
  <p>Then, in my view:</p>
  
  <pre><code>{% for event in events %}
      Event Name: {{event.name}}
      Event Venue: {{event.venue.get().name}}  # is this line costly?
  {% endfor %}
  </code></pre>
  
  <p>With this method, I think that for each event, there will be <code>get()</code> call for its respective venue. If this is true, it sounds expensive. Assuming that there are 100 events. Each page load would incur 100 <code>event.venue.get().name</code> requests. This means that a modest 10000 page views per day would incur <strong>10000 * 100</strong> .get() requests. Does that sound correct?</p>
  
  <p>Is this the best approach to this problem? If not, what options can I consider?</p>