了解 GAE 中的 ListProperty 后端行为

发布于 2024-12-17 02:05:26 字数 398 浏览 3 评论 0原文

我试图了解您应该如何访问 GAE db.ListProperty(db.Key) 中的项目。

示例:

Magazine db.Model 实体有一个 db.ListProperty(db.Key),其中包含 10 个 Article 实体。我想获取杂志对象并显示文章名称和日期。我是否对实际的文章对象进行 10 次查询?我是否进行批量查询?如果有 50 篇文章怎么办? (不要批量查询依赖于 IN 运算符,元素数量限制为 30 个或更少?)

I'm trying to understand how you're supposed to access items in a GAE db.ListProperty(db.Key).

Example:

A Magazine db.Model entity has a db.ListProperty(db.Key) that contains 10 Article entities. I want to get the Magazine object and display the Article names and dates. Do I make 10 queries for the actual article objects? Do I do a batch query? What if there's 50 articles? (Don't batch queries rely on the IN operator, which is limited to 30 or fewer elements?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

嘴硬脾气大 2024-12-24 02:05:26

因此,您描述的是这样的内容:

class Magazine(db.Model):   
    ArticleList = db.ListProperty(db.Key)

class Article(db.Model):
    ArticleName = db.StringProperty()
    ArticleDate = db.DateProperty()

在这种情况下,获取列出的文章的最简单方法是使用 Model.get() 方法,该方法查找关键列表。

m = Magazine.get() #grab the first record

articles = Article.get(m.ArticleList) #get Articles using key list

for a in articles:
    name = a.ArticleName
    date = a.ArticleDate
    #do something with this data

根据您计划如何处理数据,您最好将杂志引用属性添加到您的文章实体中。

So you are describing something like this:

class Magazine(db.Model):   
    ArticleList = db.ListProperty(db.Key)

class Article(db.Model):
    ArticleName = db.StringProperty()
    ArticleDate = db.DateProperty()

In this case the simplest way to grab the listed articles is to use the Model.get() method, which looks for a key list.

m = Magazine.get() #grab the first record

articles = Article.get(m.ArticleList) #get Articles using key list

for a in articles:
    name = a.ArticleName
    date = a.ArticleDate
    #do something with this data

Depending on how you plan on working with the data you may be better off adding a Magazine reference property to your Article entities instead.

春风十里 2024-12-24 02:05:26

您需要阅读建模实体关系,尤其是一对多的部分。

You need to read Modeling Entity Relationships, especially the part about one to many.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文