Google app engine 覆盖ndb.Model构造函数
我有一个nbd模型,定义如下:Google app engine 覆盖ndb.Model构造函数,google-app-engine,app-engine-ndb,Google App Engine,App Engine Ndb,我有一个nbd模型,定义如下: class Attachment(ndb.Model): id = ndb.StringProperty(indexed=True) mime_type = ndb.StringProperty() contents = ndb.StringProperty() modified_date = ndb.DateTimeProperty(auto_now_add=True)
class Attachment(ndb.Model):
id = ndb.StringProperty(indexed=True)
mime_type = ndb.StringProperty()
contents = ndb.StringProperty()
modified_date = ndb.DateTimeProperty(auto_now_add=True)
def __init__(self, *args, **kwargs):
super(Attachment, self).__init__(*args, **kwargs)
根据文档和BDFL的指示,您可以通过调用上面的super()
来覆盖ndb.Model子类中的\uuuuuu init\uuuuu
;但是,每次我尝试创建一个新实例时,如下所示:
Attachment(id='soke',mime\u type='img/jpeg')
不断抛出那些参数意外的错误
我错过了什么?非常感谢您的帮助。好吧,看来我把模型定义搞砸了,是因为神的安排才工作的。相关文件: 您无法轻松定义名为“key”、“id”、“parent”或“namespace”的属性。例如,如果在构造函数或populate()调用中传递key=“foo”,它将设置实体的键,而不是名为“key”的属性属性
在我开始尝试覆盖
\uuuu init\uuuu()
methodYes id之前,我应该澄清一下,过去使用的模型工作得非常好。。您可以看到它,就像附件.key.id()一样,它是一个数字id,除非您使用了密钥_name@GuidovanRossum我会的,两天后我才被允许这么做。