When I need 1 for many, I use duplicate keyProperties. The code:
class Subject(ndb.Model): name = ndb.StringProperty() class Student(ndb.Model): name = ndb.StringProperty() subjects = ndb.KeyProperty(kind='Subject', repeated=True)
template:
{% for subject in student.subjects %} {{subject.get().name}} {% endfor %}
ndb is nosql, so you will not find a reference to the parent in the child. However, you can add it like this. Do not forget to specify the key value for the student when creating a new object.
class Subject(ndb.Model): name = ndb.StringProperty() student = ndb.KeyProperty(kind='Student') class Student(ndb.Model): name = ndb.StringProperty() subjects = ndb.KeyProperty(kind='Subject', repeated=True)
user11012
source share