【问题标题】:How to remove value from GAE NDB Property (type BlobKeyProperty)如何从 GAE NDB 属性中删除值(类型 BlobKeyProperty)
【发布时间】:2014-02-24 13:56:45
【问题描述】:

这可能是最愚蠢的问题,我对此表示歉意,但我很困惑

我有以下实体:

class Profile(ndb.Model):  
    name = ndb.StringProperty()  
    identifier = ndb.StringProperty()  
    pic = ndb.BlobKeyProperty() # stores the key to the profile picture blob 

我想删除上述实体的“pic”属性值,使其看起来像从未为“pic”分配任何值一样新鲜。我不打算删除完整的实体。以下方法是否正确:

qry = Profile.query(Profile.identifier==identifier) 
result_record_list = qry.fetch()  
if result_record_list:  
    result_record_list[0].pic.delete()  # or result_record_list[0].pic = none # or undefined or null 

我正在单独删除此 blob 键引用的实际 blob

【问题讨论】:

    标签: google-app-engine python-2.7 app-engine-ndb


    【解决方案1】:

    为其分配 None 并将其放回数据存储区。

    result_record_list[0].pic = None
    result_record_list[0].put()
    

    【讨论】:

    • 感谢 omair_77 的回复
    【解决方案2】:

    数据存储是一个 OO 无模式数据库。因此,您可以在 Kind (ndb.Model) 中添加和删除属性,而无需更新架构。

    如果您还想清理实体,请查看this anwser from Guido

    【讨论】:

    • 感谢 voscausa 的回复
    猜你喜欢
    • 2012-09-23
    • 2016-10-29
    • 2015-02-19
    • 1970-01-01
    • 2022-01-20
    • 2011-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多