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

查看:79
本文介绍了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. 在此模型中,我接收的是actual实体,而不是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天全站免登陆