MongoUtil.py 文件源码

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

项目:restful-api 作者: TeamGhostBuster 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号