def api_delete_one(collection, item_id):
'''
delete one document from a certain collection
'''
if not g.__user__.get('admin'):
return make_response('Permission denied.', 403)
if collection == 'comments':
blog_id = db.comments.find_one({'_id': ObjectId(item_id)}).get('blog_id')
db[collection].delete_one({'_id': ObjectId(item_id)})
if collection == 'blogs':
db.comments.delete_many({'blog_id': ObjectId(item_id)})
if collection == 'comments':
return redirect(url_for('api.api_get_blog_comments', blog_id=blog_id))
return jsonify(item_id=item_id)
评论列表
文章目录