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()
评论列表
文章目录