title: Google app engine ReferenceProperty relationships
body: <p>I'm trying to get my models related using ReferenceProperty, but not have a huge amount of luck. I have 3 levels: Group, Topic, then Pros, and Cons. As in a Group houses many topics, and within each topic could be many Pros and Cons.</p>
  
  <p>I am able to store new Groups nice and fine, but I don't have any idea how to store topics underneath these groups. I want to link from a page with a link "New topic" underneath each group, that takes them to a simple form (1 field for now). Obviously the URL will need to have some sort of reference to the id of the group or something.</p>
  
  <p>Here are my models: </p>
  
  <pre><code>class Groups(db.Model):
  
      group_user = db.UserProperty()
      group_name = db.StringProperty(multiline=True)
      group_date = db.DateTimeProperty(auto_now_add=True)
  
  
  class Topics(db.Model):
  
      topic_user = db.UserProperty()
      topic_name = db.StringProperty(multiline=True)
      topic_date = db.DateTimeProperty(auto_now_add=True)
      topic_group = db.ReferenceProperty(Groups, collection_name='topics')
  
  class Pro(db.Model):
  
      pro_user = db.UserProperty()
      pro_content = db.StringProperty(multiline=True)
      pro_date = db.IntegerProperty(default=0)
      pro_topic = db.ReferenceProperty(Topics, collection_name='pros')    
  
  class Con(db.Model):
  
      con_user = db.UserProperty()
      con_content = db.StringProperty(multiline=True)
      con_date = db.IntegerProperty(default=0)
      con_topic = db.ReferenceProperty(Topics, collection_name='cons')    
  </code></pre>
  
  <p>And one function for the actual page I want to show the list of Groups, and then underneath their topics:</p>
  
  <pre><code>class Summary(webapp.RequestHandler):
      def get(self):
  
          groups_query = Groups.all()
          groups = groups_query.fetch(1000)
          template_values = {
  
              'groups': groups,           
          }
  
          path = os.path.join(os.path.dirname(__file__), 'summary.html')
          self.response.out.write(template.render(path, template_values))
  </code></pre>
  
  <p>And finally the html:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      &lt;a href="/newgroup"&gt;New Group&lt;/a&gt;
      &lt;br&gt;
      {% for group in groups %}
  
      &lt;font size="24"&gt;{{ group.group_name|escape }}&lt;/font&gt;&lt;br&gt; by &lt;b&gt;{{ group.group_user }}&lt;/b&gt; at &lt;b&gt;{{ group.group_date }}&lt;/b&gt; {{ group.raw_id }}
      &lt;br&gt;
      &lt;a href="/newtopic?id={{group.key.id}}" &gt;New topice &lt;/a&gt;
      &lt;br&gt;
      &lt;blockquote&gt;
          {{ topics.topics_name }}
      &lt;/blockquote&gt;
  
  
      {% endfor %}
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>