具有动态TextProperty的NDB Expando模型?

cri*_*aig 1 python google-app-engine

我正在尝试:

MyModel({'text': db.Text('text longer than 500 byets')})
Run Code Online (Sandbox Code Playgroud)

但得到:

BadValueError: Indexed value fb_education must be at most 500 bytes
Run Code Online (Sandbox Code Playgroud)

我认为这只是旧db api从这个问题的延续.

https://groups.google.com/forum/?fromgroups#!topic/google-appengine/wLAwrjtsuks

Vij*_*ani 5

首先动态创建实体:

 kindOfEntity = "MyTable"
class DynamicEntity(ndb.Expando):
     @classmethod
     def _get_kind(cls):
        return kindOfEntity
Run Code Online (Sandbox Code Playgroud)

然后分配文本属性运行时间/动态,如下所示

dbObject = DynamicEntity()
key = "studentName"
value = "Vijay Kumbhani"
textProperties = ndb.TextProperty(key)
dbObject._properties[key] = {}
dbObject._values[key] = {}
dbObject._properties[key] = textProperties 
dbObject._values[key] = value
dbObject.put()
Run Code Online (Sandbox Code Playgroud)

在使用Text属性分配关键属性之后