当前位置: 首页>>代码示例>>Python>>正文


Python TaggedItem.save方法代码示例

本文整理汇总了Python中taggit.models.TaggedItem.save方法的典型用法代码示例。如果您正苦于以下问题:Python TaggedItem.save方法的具体用法?Python TaggedItem.save怎么用?Python TaggedItem.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在taggit.models.TaggedItem的用法示例。


在下文中一共展示了TaggedItem.save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _delete_and_recreate_tags

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import save [as 别名]
def _delete_and_recreate_tags(slug):
    source_demo = Submission.objects.using("default").get(slug=slug)
    destination_demo = Submission.objects.using("new").get(slug=slug)
    source_type, destination_type = _get_demo_content_types()

    source_tags = source_demo.taggit_tags.all()
    source_tags_names = [tag.name for tag in source_tags]
    destination_tags = destination_demo.taggit_tags.using("new").all()
    destination_tags_names = [tag.name for tag in destination_tags]

    if source_tags_names == destination_tags_names:
        logger.info(
            "%s: Found %s matching tag(s): %s" % (source_demo.slug, len(destination_tags), destination_tags_names)
        )
        return destination_tags
    else:
        dest_demo_tagged_items = TaggedItem.objects.using("new").filter(
            tag__in=[tag for tag in destination_tags], object_id=destination_demo.id, content_type=destination_type
        )
        dest_demo_tagged_items.using("new").delete()
        logger.info("%s: Migrating %s tag(s): %s" % (source_demo.slug, len(source_tags), source_tags_names))
        for source_tag in source_tags:
            try:
                destination_tag = Tag.objects.using("new").get(name=source_tag.name)
            except Tag.DoesNotExist:
                destination_tag = Tag(name=source_tag.name)
                destination_tag.save(using="new")
            destination_demo_tag = TaggedItem(
                content_type=destination_type, object_id=destination_demo.id, tag=destination_tag
            )
            destination_demo_tag.save(using="new")
    return destination_tags
开发者ID:jamonation,项目名称:kuma,代码行数:34,代码来源:migrate_demos.py

示例2: _add_tags

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import save [as 别名]
def _add_tags(obj, tags_str, creator, content_type_name):
    for tag_name in tags_str.split(','):
        tag_name = tag_name.strip()
        # don't recreate the tag if it already exists
        try:
            t = Tag.objects.get(slug=slugify(tag_name))
        except ObjectDoesNotExist as dne:
            t = Tag()
            t.name = tag_name[:99]
            t.slug = slugify(tag_name)
            t.save()
        ti = TaggedItem()
        ti.tag = t
        ti.object_id = obj.id
        ti.tag_creator = creator
        ti.content_type = ContentType.objects.filter(name=content_type_name)[0]
        ti.save()
开发者ID:makaimc,项目名称:pfisdi,代码行数:19,代码来源:__init__.py

示例3: set_taggeditems

# 需要导入模块: from taggit.models import TaggedItem [as 别名]
# 或者: from taggit.models.TaggedItem import save [as 别名]
 def set_taggeditems(self):
     objects = OldTaggedItem.objects.all()
     print objects.count()
     for old_tagitem in objects:
         old_id = old_tagitem.tag_id
         new_id = self.dupemap.get(old_id, old_id)
         new_tags = NewTag.objects.filter(id=new_id)
         if new_tags:
             new_tag = new_tags[0]
             new_tagitem = NewTaggedItem(
                 id=old_tagitem.id,
                 tag=new_tag,
                 content_type=old_tagitem.content_type,
                 object_id=old_tagitem.object_id,
             )
             new_tagitem.save()
     print NewTaggedItem.objects.count()
开发者ID:thatzprem,项目名称:django-nano,代码行数:19,代码来源:migrate_tagging_to_taggit.py


注:本文中的taggit.models.TaggedItem.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。