我存储了不需要的数据,因此我想清理它。我可以从数据存储迁移到 blobstore,因此至少字段 small=db.BlobProperty(default=None)
是多余的,因此我想将其删除,并将其从实体中删除数据存储区,因为名为“full”的变量已经具有原始图像,而名为“small”的变量是我可以从 blobstore 获取的调整大小,或者如果图像尚未迁移,我可以调整内存中属性“full”的大小从而删除重复和冗余的数据。
但是如何从存储的实体中删除属性?我想保留此类并将 blobproperties 移至 blobstore,然后删除 blobproperties,因此我想我必须编写一个 python 脚本来迭代实体并将变量 small
设置为 None 和/或从所有实体中删除名为 small
的变量。你能建议如何做吗?
class Image(db.Model):#migrate to blobstore
reference=db.ReferenceProperty(A,collection_name='matched_images',verbose_name="Title")
primary_image = blobstore.BlobReferenceProperty()
title=db.StringProperty(multiline=True,verbose_name="Title")
avatar=db.BlobProperty(default=None)
text=db.TextProperty(default=None)
name=db.StringProperty(default=None)
email=db.EmailProperty(indexed=False,verbose_name="Email")
name=db.StringProperty()
desc=db.StringProperty()
owner=db.UserProperty()
secret=db.StringProperty()
full=db.BlobProperty(default=None)
full_ext=db.StringProperty()
small=db.BlobProperty(default=None)
small_ext=db.StringProperty()
像下面这样的东西会起作用吗?
# will DELETE the small property use /deletemodels?force=true
class DeleteSmallProperties(webapp.RequestHandler):
def get(self):
def dMsg(msg):
self.response.out.write(msg + '\n')
n = self.request.get('force')
if n:
dMsg('clearing Image.small data....')
for uc in Image.all():
uc.small = None #(?)
uc.save() #or us.put()?
dMsg('.')
如何删除它而不只是将其设置为“无”?
最佳答案
我会选择 Mapreduce api在这种情况下,这应该是完成这项工作的最佳工具*:
1.注册映射器
2.更新实体
from mapreduce import operation as op
def process(entity):
entity.small = None
yield op.db.Put(entity)
* 如果实体数量不是那么大,您可以使用简单的 python 脚本简单地迭代每个实体
关于python - 如何从多个实体中删除 db.BlobProperty?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7373741/