AppEngine NDB 属性验证 [英] AppEngine NDB property validations

查看:29
本文介绍了AppEngine NDB 属性验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道验证 NDB 实体属性的最佳方法是什么:

I wonder what the best approach is for validating NDB entity properties likes:

  • 日期必须在未来
  • 等级(整数属性)必须介于 1 到 10 之间
  • 对另一个实体的引用必须具有某些属性值(例如 book.category.active 必须为 True)

我也在使用 WTForms 来验证提交的请求,但我也想在数据存储实体本身等较低级别上强制执行验证.

I'm also using WTForms to validate submitted requests, but I want to enforce validations also on a lower level like the datastore entities itself.

所以基本上我正在寻找的是对数据存储实体调用验证以查看它是否有效.如果它有效,我可以将实体放入数据存储区,但如果它无效,我想检索无效的属性,包括未成功验证的应用验证器.

So basically what I'm looking for is to call a validate on a datastore entity to see if it's valid or not. In case it's valid I can put the entity to the datastore, but if it's not valid I want to retrieve the invalid properties including the applies validator that did not validate successfully.

WTForms 可能不够用的另一个原因是我正在体验新的 Cloud Endpoints.在这个模型中,我接收的是实际实体,而不是 http 请求.

Another reason WTForms might not be sufficient is that I'm experiencing with the new Cloud Endpoints. In this model I'm receiving the actial entity and not a http request.

其他 AppEngine 用户如何解决这个问题?

How are other AppEngine users solving this?

推荐答案

这并不总是最好的解决方案,但您可以推出自己的解决方案.只需使用 reg-exs/mins 和 maxs 等预先定义一堆属性.看起来您的属性足够直接,不会太难.

Not this is is always the best solution, but you could roll your own. Just pre-define a bunch of properties with reg-exs/mins and maxs etc. It seems like your properties are straight forward enough that it wouldn't be too difficult.

这篇关于AppEngine NDB 属性验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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