Google App Engine的“webapp”中是否有“ForeignKey”? [英] Is there something like `ForeignKey` in Google App Engine's `webapp`?

查看:173
本文介绍了Google App Engine的“webapp”中是否有“ForeignKey”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google App Engine和 webapp 框架。在 webapp 中有没有像Django的 ForeigKey ?即我有一个模型,我希望它有一个属性/字段指向另一个模型。可能吗?

解决方案

db.ReferenceProperty 。在使用它时需要注意两点:自动解引用(这是另一个数据存储RPC调用),被引用的实体不需要存在(所以你需要手动检查它)。

当使用db.ReferenceProperty时,确保使用Appstats来避免串行读取实体。 Nick Johnson有一篇文章,获取引用的实体。


I'm using Google App Engine with their webapp framework. Is there something like Django's ForeigKey in webapp? i.e. I have a model and I want it to have a property/field that points at another model. Possible?

解决方案

There is a db.ReferenceProperty. You need to be aware of two things when using it: automatic dereferencing (which is another datastore RPC call) and the entity being referenced is not required to exist (so you will need to manually check it).

When using db.ReferenceProperty make sure you use Appstats to avoid fetching entities in serial. Nick Johnson has an article that explains how to pre-fetch referenced entities.

这篇关于Google App Engine的“webapp”中是否有“ForeignKey”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆