I am trying to create ndb.Model class like Students and subjects
class Subject(ndb.Model):
name = ndb.StringProperty()
class Student(ndb.Model):
na
When I need 1 to many I use repeated keyProperties. 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 reference to the parent in the child. However, you could add it like that. Don't forget to set student key value when creating a new subject.
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)