【发布时间】:2012-06-22 18:48:42
【问题描述】:
我已阅读this question 和简单明了的答案,但在我的情况下它没有用,因为答案不考虑嵌套的for。请看代码:
class SuperCat(ndb.Model):
class Category(ndb.Model):
supercat = ndb.KeyProperty(kind=SuperCat)
class SubCat(ndb.Model):
category = ndb.KeyProperty(kind=Category)
处理程序:
Categories = ndb.gql("SELECT * FROM Category WHERE supercat = :1", supercat_key)
self.generate('supercat.html', {'Categories': Categories})
在模板中,使用旧的 db.Model 和反向引用属性就足够了:
{{ for Category in Categories }}
{{ for SubCat in Category.subcat_set }} # this is the back-reference in action
提供这种数据结构的同样简单的替代方案是什么?
【问题讨论】:
-
似乎Structured Properties 是一个很好的起点..
标签: google-app-engine app-engine-ndb