From 01b9f7d9525721c9072d6b602cbbed8f9165adbd Mon Sep 17 00:00:00 2001 From: CharlesDDDD <10185101155@stu.ecnu.edu.cn> Date: Mon, 11 Jan 2021 21:38:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86collection=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD=20=E8=87=AA=E5=8A=A8=E5=88=B7?= =?UTF-8?q?=E6=96=B0order?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/view/collection.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/APP/view/collection.py b/APP/view/collection.py index 25785c3..920eba1 100644 --- a/APP/view/collection.py +++ b/APP/view/collection.py @@ -4,6 +4,7 @@ import random from APP.view.database import db_session from APP.view.model import Collection, UserLike import uuid + bp_collection = Blueprint("collection", __name__, url_prefix="/collection") @@ -16,7 +17,7 @@ def add_collection(): try: count = Collection.query.count() print(count) - c = Collection(id=id, name=name, tag=tag, phonenum=phonenum,order=count) + c = Collection(id=id, name=name, tag=tag, phonenum=phonenum, order=count) db_session.add(c) db_session.commit() except BaseException as e: @@ -195,6 +196,21 @@ def delete(): """ 删除这个id的collection,记得刷新顺序 """ + try: + # 删除collection + item = db_session.query(Collection).filter(Collection.id == id).first() + order_item = item.order + db_session.delete(item) + + # 刷新order顺序 + db_session.query(Collection).filter(Collection.order > order_item).update( + {Collection.order: Collection.order - 1}) + db_session.commit() + except BaseException as e: + print(str(e)) + ret = {'msg': 'failed!'} + return json_util.dumps(ret) + ret = {'msg': 'succuss'} return json_util.dumps(ret)