forms.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:website 作者: hackerspace-ntnu 项目源码 文件源码
def change_tags(items_str: str, new_tags: str):
        """ Updates the tags for items in item_str to the tags in new_tags
        Args:
            items_str, new_tags: id's separated with '_' (also at the end)
        """
        tags = [get_object_or_404(Tag, pk=tag_id) for tag_id in new_tags.split('_')[:-1]]
        items = [get_object_or_404(Item, pk=item_id) for item_id in items_str.split('_')[:-1]]
        for item in items:
            item.tags.remove(*item.tags.all())
            item.tags.add(*tags)
            item.save()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号