def partition_user_list(user, old_list_id, new_list_name, articles):
try:
# Get list and create new list
old_list = List.objects.get(id=ObjectId(old_list_id))
new_list = create_list(new_list_name, user)
article_buffer = list()
for a in articles:
article_buffer.append(Article.objects.get(id=ObjectId(a)))
# Add selected article into new list and remove from old list
List.objects(id=new_list.id).update_one(add_to_set__articles=article_buffer)
List.objects(id=old_list.id).update_one(pull_all__articles=article_buffer)
except Exception as e:
print(type(e).__name__)
return type(e).__name__
old_list.reload()
new_list.reload()
return old_list, new_list
评论列表
文章目录