本文整理汇总了Python中models.Tag.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.insert方法的具体用法?Python Tag.insert怎么用?Python Tag.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import insert [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: add_tags
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import insert [as 别名]
def add_tags(blog_id,tags):
if not tags:
return
if not tags[0]:
return
for tag in tags:
t=Tag.find_by('where name=?',tag)
if t:
t = t[0]
if not t:
t = Tag(name=tag)
t.insert()
bt = BlogTag(blog_id=blog_id,tag_id=t.id)
tag_count_add(t)
bt.insert()
logging.info("######add tag %s----%s" % (blog_id,tag))