- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到了这个功能(?),其中字典隐式转换为 ndb.Model 对象
我有以下ndb.Model类
class DateOfBirth(ndb.Model)
day = ndb.IntegerProperty()
month = ndb.IntegerProperty()
year = ndb.IntegerProperty()
class User(ndb.Model):
dob = ndb.StructuredProperty(DateofBirth)
在一个地方,当我不小心传入一个字典时
user.dob = {"日": 12, "月": 10, "年": 1983}
它没有提示,而且看起来很有效。
这是预期的吗,还是我预计以后会遇到问题(因为这种行为没有记录并且预计会随时中断)
最佳答案
这对我来说是一个惊喜,我已经使用NDB很长时间了!但从代码来看,似乎是有意为之:https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/caac0c3e7dd4d9b2c6b32dfc5d59386dd02e6b57/ndb/model.py#L2354
只需对代码进行很小的更改即可不必依赖该行为:
user.dob = DateOfBirth(**{"day": 12, "month": 10, "year": 1983})
关于python - Python Google App Engine 中隐式 dict 到 ndb.Model 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40690083/
如果我有一个具有以下定义的Contact 模型: class Contact(ndb.Model): name = ndb.TextProperty(indexed=False) we
我有 webapp2 服务,它在多个不相互依赖的 NDB 模型中插入条目。现在我们要求的是服务应该在事务中。那是服务失败然后它应该恢复完整的交易(例如,如果一个条目插入到第一个和第二个模型中,并且在该
切换到 python GAE 上的 ndb 库。 我可以将 ndb 与之前使用低级 api 创建的实体一起使用吗?还是我必须复制所有旧实体并重新保存它们才能使用 ndb? 谢谢! 最佳答案 ndb 只
是否可以在 pre_put_hook 中找出实体的脏因子? 我想根据put 的内容有条件地执行一些回调。例如。如果实体的特定属性发生更改,我想发送邮件通知。我可以在调用 put() 之前手动执行此操作
我是谷歌应用引擎和 NDB 的初学者。我的问题:如果我在模型中有 1 个实体, 我想防止 2 个并行操作时发生冲突,代码示例: class MyModel(ndb.Model) count = n
假设有一个看起来像这样的 ndb.Model: class Foo(ndb.Model): bar = ndb.StringProperty() 我的问题是,如果我的唯一输入是 Foo.query
给定我构造的 key ,我想访问数据存储区以查看它是否存在,但我想要最便宜(及时)的方法来做到这一点。我正在寻找的就像一个只有键的查询,但是来自 get,例如my_key.get(keys_only=
https://developers.google.com/appengine/docs/python/ndb/ https://developers.google.com/appengine/doc
我有一个 ndb.Model,它有一个 ndb.DateTimeProperty 和一个 ndb.CompulatedProperty,它使用 ndb.DateTimeProperty 创建时间戳。
我计划将 Odoo 移植到 Google App Engine Web 应用程序。当我知道 Odoo 使用 postgresql 时,是否可以将数据库连接、查询和所有从 Postgresql db 移
我有一个 POST 方法,它调用一些 tasklet。这些 tasklet 确实有 yield ,我的代码中确实有一些 x.put_async()。所以我不希望它在所有异步内容完成之前返回。所以我用
我有一个简单的 NDB 模型: from google.appengine.ext import ndb import logging from libs import Api class User(
使用 Python NDB 的新手。 我有类似的东西: class User(ndb.Model): seen_list = nbd.KeyProperty(kind=Survey, repe
我的应用程序中有以下查询 query = cls.query().filter(cls.taskgroup_id == taskgroup_id, cls.availability == True,
我在 NDB 迁移方面遇到问题。目前,我在 NDB Cluster 中有 2 个副本。我想将集群移至新硬件中。因此,在新机器中,我设置了 datanodes 和 sqlnodes 并将管理节点指向旧集
我有一个 mysql ndb 集群(详情如下)。问题是当我做最简单的事情时,例如恢复使用 mysqldump 转储的数据库,它需要绝对的时间! IE 6 小时恢复一个大小为 745MB 且在大约 30
来自 What can be done in a transaction (我的重点): All Datastore operations in a transaction must operate
我正在对 Expense 模型的方法进行单元测试。模型的相关部分如下所示: class Expense(ndb.Model): user = ndb.KeyProperty(User, req
几年来,我一直在使用类似于下面复制的代码片段。 基本思想是 Person 可以结婚,当他们结婚时,我创建一个“Marriage”实体。一个人只能结婚一次,所以我有一个 bool 值来指示这个人是否已婚
我们使用的是 ndb 数据存储、python、标准谷歌应用引擎。我们想使用查询游标。但是为了根据 here 工作和 here ,看起来我们需要实现 datastore_model.query().or
我是一名优秀的程序员,十分优秀!