本文整理汇总了Python中tag.Tag.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.by_name方法的具体用法?Python Tag.by_name怎么用?Python Tag.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tag.Tag
的用法示例。
在下文中一共展示了Tag.by_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_tag_by_name
# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import by_name [as 别名]
def add_tag_by_name(self, tag_name, vocab=None, autoflush=True):
"""Add a tag with the given name to this package's tags.
By default the given tag_name will be searched for among the free tags
(tags which do not belong to any vocabulary) only. If the optional
argument `vocab` is given then the named vocab will be searched for the
tag name instead.
If no tag with the given name is found, one will be created. If the
optional argument vocab is given and there is no tag with the given
name in the given vocabulary, then a new tag will be created and added
to the vocabulary.
"""
from tag import Tag
if not tag_name:
return
# Get the named tag.
tag = Tag.by_name(tag_name, vocab=vocab, autoflush=autoflush)
if not tag:
# Tag doesn't exist yet, make a new one.
if vocab:
tag = Tag(name=tag_name, vocabulary_id=vocab.id)
else:
tag = Tag(name=tag_name)
assert tag is not None
self.add_tag(tag)
示例2: add_tag_by_name
# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import by_name [as 别名]
def add_tag_by_name(self, tagname, autoflush=True):
from tag import Tag
if not tagname:
return
tag = Tag.by_name(tagname, autoflush=autoflush)
if not tag:
tag = Tag(name=tagname)
if not tag in self.tags:
self.tags.append(tag)