本文整理汇总了Python中models.Article.update方法的典型用法代码示例。如果您正苦于以下问题:Python Article.update方法的具体用法?Python Article.update怎么用?Python Article.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import update [as 别名]
def post(self):
"""Edit Artilce."""
data = self.request.data(title='', tag='', category='', \
raw_content='', old_tag='', created_at='')
created_at = data.created_at
title = data.title
old_tag = data.old_tag
tag = data.tag
category = data.category
raw_content = data.raw_content
content = (markdown2.markdown(raw_content)).encode('utf-8')
u_id = self.get_current_user()
admin = User.get_by_primary_key(u_id)
created_at_now = int(time.time())
# new article
if not created_at:
article = Article(title=title,content=content,\
raw_content=raw_content,category=category, \
author=admin.name, created_at=created_at_now)
article.insert()
new_article = Article.select_one('created_at=?', created_at_now)
article_id = new_article.id
# tag
tag_d = Tag.select_one('tag_name=?', tag)
# tag doesn't exists
if not tag_d:
new_tag = Tag(tag_name=tag)
new_tag.insert()
get_tag = Tag.select_one('tag_name=?', tag)
tag_id = get_tag.id
# tag exists
else:
tag_id = tag_d.id
article_tag = ArticleTag(article_id=article_id, tag_id=tag_id)
article_tag.insert()
# update old article
else:
article = Article(title=title, content=content, \
raw_content=raw_content, author=admin.name, \
category=category, created_at=created_at_now)
article.update('created_at=?', created_at)
new_article = Article.select_one('created_at=?', created_at_now)
article_id = new_article.id
old_tag = Tag.select_one('tag_name=?', old_tag)
new_tag = Tag(tag_name=tag)
other_article_tag = ArticleTag.select_all('tag_id=?', old_tag.id)
# other article doesn't have this article
if len(other_article_tag) >= 1:
tag_id = old_tag.id
new_tag.update('id=?', tag_id)
# other article has this tag
else:
new_tag.insert()
get_tag = Tag.select('tag_name=?', tag)
tag_id = get_tag.id
article_tag = ArticleTag(tag_id=tag_id)
article_tag.update('article_id=?', article_id)
self.redirect('/admin/articles')
示例2: process_item
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import update [as 别名]
def process_item(self, item, spider):
try:
rows = Article.select().where(Article.id == int(item['url'].split('/')[-1]))
for row in rows:
if row:
Article.update(title=item['title'], url=item['url'], read_count=item['read_count'],
comment_count=item['comment_count'], update_time=datetime.datetime.now())\
.where(Article.id == int(item['url'].split('/')[-1])).execute()
else:
Article.create(id=int(item['url'].split('/')[-1]), title=item['title'], url=item['url'], read_count=item['read_count'],
comment_count=item['comment_count'], create_time=datetime.datetime.now(),
update_time=datetime.datetime.now())
except Exception, e:
print e