【发布时间】:2014-07-15 12:12:51
【问题描述】:
我将 72x72 编码的 base64 缩略图存储在 ndb.TextProperty() 中
模型结构类似于:
class Article(ndb.Model):
title = ndb.StringProperty()
body = ndb.TextProperty()
tags = ndb.StringProperty(repeated=True, indexed=True)
thumbnail = ndb.TextProperty()
has_thumbnail = ndb.ComputedProperty(
lambda self: True if self.thumbnail else False)
enable = ndb.BooleanProperty(default=True)
使用投影查询的方法是:
@classmethod
def get_articles(cls):
q = Aricle.query(
True == Article.enable,
projection = [
Article.title
Article.has_thumbnail
])
return q.get()
由于 ndb.TextProperty() 未编入索引,我无法将它们放在预测中,因此我尝试使用 ndb.ComputedProperty 并注意到它正在工作。
我的主要问题是知道这是否是一种正确的查询方式,基本上我只想查询返回文章的标题和缩略图,或者知道文章是否有缩略图。
【问题讨论】:
标签: python python-2.7 google-app-engine google-cloud-datastore app-engine-ndb