同类实体组

2024-09-27 21:31:52 发布

您现在位置:Python中文网/ 问答频道 /正文

让我们举一个例子,我运行了一个博客,它自动更新文章。你知道吗

我想在两个不同的“组”中保留一个类(=model)BlogPost实体,一个称为“未来blogposts”,另一个称为“过去blogposts”。你知道吗

这是一个合理的划分,将使我能够有效地处理我的博客文章(分别查询它们等)。你知道吗

基本上,问题是我的模型的“种类”永远是“BlogPost”。那我怎么才能把它分成两组呢?

以下是我目前找到的选项:

  • Duplicating the same model class code twice (once FutureBlogPost class and once PastBlogPost class (so their kinds will be different)) -- seems quite ridiculous.

  • Putting them under different anchestors (FutureBlogPost, "SomeConstantValue", BlogPost, #id) but this method also has its implications (1 write per second?) and also the whole ancestor-child relationship doesn't seem fit here. (and why do I have to use "SomeConstantValue" if I choose that option?)

  • Using different namespaces -- seems too radical for such a simple separation

正确的方法是什么?你知道吗


Tags: andthe实体model文章class例子also
2条回答

看来我终于找到了相关的文章。你知道吗

据我所知,按特定类型拉取所有实体和按特定属性拉取它们没有区别,两者都需要相同类型的后台工作。 (但是,通过特定的完整密钥进行查询的速度更快)

因此,基本上,添加一个名为“Type”的属性或任何其他要用于将特定实体拆分为组的属性,与赋予它某种属性一样有用。你知道吗

阅读更多信息:https://developers.google.com/appengine/articles/storage_breakdown

如您所见,EntitiesByKind和EntitiesByProperty都只是原始键的索引表。你知道吗

最后,一个答案。你知道吗

为什么不在“BlogPost”实体中添加一个布尔值,如果它是过去的,则为0,如果它是未来的,则为1?可以让您轻松地分别查询它们。你知道吗

相关问题 更多 >

    热门问题