Google app engine ReferenceProperty relationships

前端 未结 4 1251
别那么骄傲
别那么骄傲 2021-01-07 07:39

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 ma

4条回答
  •  攒了一身酷
    2021-01-07 08:04

    I'm not quite sure what problem you're having. Everything you list looks fine - the ReferenceProperties are set up according to what one would expect from your dscription. The only problem I can see is that in your template, you're referring to a variable "topics", which isn't defined anywhere, and you're not iterating through the topics for a group anywhere. You can do that like this:

    
      
        New Group
        
    {% for group in groups %} {{ group.group_name|escape }}
    by {{ group.group_user }} at {{ group.group_date }} {{ group.raw_id }}
    New topice
    Topics:
      {% for topic in group.topics %}
    • {{topic.topic_name}}
    • {% endfor %}
    {% endfor %}

    To create a new topic, just use the constructor, passing in the required arguments:

    mytopic = Topic(topic_name="foo", topic_group=somegroup)
    

    Here, somegroup should be either a Group object, or a key for a Group object.

提交回复
热议问题