【发布时间】:2011-08-16 21:49:50
【问题描述】:
有没有办法将一个模型中的所有属性设置为 True 到另一个模型? 我正在用 Python 编写并具有以下内容:
class crimechecker(webapp.RequestHandler):
def get(self):
#Checks for crime
articles = Article.all().filter('crime = ', None)
for article in articles:
crime = False
for word in triggers:
body = article.body
if body.find(word) != -1:
crime = True
article.crime = crime
a = article.put()
然后运行一个单独的 cron:每个犯罪故事都将添加到 Story 及其位置。 但是故事没有出现在故事模型中?!
class place(webapp.RequestHandler):
def post(self):
# Check for any article which was classified as "TRUE" therefore it is a crime document
crimes = Article.all().filter('crime = ', True)
for crimestory in crimes:
if Story.all().filter('title = ', crimestory.title).count() == 0:
#Yahoo Placemaker key
p = placemaker('HSnG9pPV34EUBcexz.tDYuSrZ8Hnp.LowswI7TxreF8sXrdpVyVIKB4uPGXBYOA9VjjF1Ca42ipd_KhdJsKYjI5cXRo0eJM-')
#Encoding for symbols and euro signs etc.
print p.find_places(crimestory.body.encode('utf-8'))
for place in p.places:
splitted = place.name.split()
#Check for locations within Ireland (IE)
if 'IE' in splitted:
story = Story(long=place.centroid.longitude, lat=place.centroid.latitude, link=crimestory.link, loc_name=place.name, title=crimestory.title, date=crimestory.date).put()
logging.info(story)
我有 2 个模型:文章和故事。 所有文章都存储在文章模型中,并且任何带有 crime = True 的文章都设置在 Story 模型中。 出于某种原因,它没有移动故事。 cron 正在运行并且没有任何日志错误。 我可以在我的仪表板中执行此任务吗? 我已经查询了这两个模型:
SELECT * FROM Article ORDER BY date DESC
文章模型包含今天(5 月 2 日)的故事
Story 有 4 月 19 日的文章,此后不再有文章。 我可以查询模型并说将所有犯罪设置为 true 的实体移至 Story 模型吗?
【问题讨论】:
-
您的应用程序有 1 个数据库/数据存储。你有 2 个模型。
标签: python google-app-engine cron google-cloud-datastore gql