(如何)可以向 Google App Engine python 中的实体集合添加方法?
在 GAE-python 中,您可以通过为子模型分配引用属性来建模一对多关系。
class Book(db.Model):
title = db.StringProperty()
class Author(db.Model):
book = db.ReferenceProperty(Book, collection_name = 'authors')
is_primary = db.BooleanProperty()
name = db.StringProperty()
这样,我可以访问图书对象实例的 authors
属性,以获取引用它的所有 Author 实例的可查询列表。
我想要做的是用一个方法补充 authors
属性。基于前一个例子的一个简单示例是一个仅返回按字母顺序排序的主要作者的函数。这样的语法是什么?
In GAE-python, you can model a one-to-many relationship by assigning a reference property to the child model.
class Book(db.Model):
title = db.StringProperty()
class Author(db.Model):
book = db.ReferenceProperty(Book, collection_name = 'authors')
is_primary = db.BooleanProperty()
name = db.StringProperty()
This way, I can access the authors
property of a book object instance to get a query-able list of all the Author instances that reference it.
What I want to do is supplement the authors
property with a method. A trivial example based on the preceding one would be a function that returns just the primary authors sorted in alphabetical. What's the syntax for something like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是一对多的关系。没有 db.Referencelist 属性。我想这会对您有所帮助。
What you are looking for is one to many realtionship. There is no db.Referencelist property.I guess this will help you out.