From a0c2e25ebdfce44f2196cd4da1200a6cda1eca04 Mon Sep 17 00:00:00 2001 From: CharlesDDDD <10185101155@stu.ecnu.edu.cn> Date: Mon, 11 Jan 2021 21:08:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86swap=E9=9B=86?= =?UTF-8?q?=E9=94=A6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/view/collection.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/APP/view/collection.py b/APP/view/collection.py index eda09e6..ad16235 100644 --- a/APP/view/collection.py +++ b/APP/view/collection.py @@ -15,7 +15,7 @@ def add_collection(): try: count = Collection.query.count() print(count) - c = Collection(id=count + 1, name=name, tag=tag, phonenum=phonenum) + c = Collection(id=count, name=name, tag=tag, phonenum=phonenum) db_session.add(c) db_session.commit() except BaseException as e: @@ -170,6 +170,20 @@ def swap(): 把这个id的collection和顺序是order的collection交换 编号从零开始,有可能是自己 """ + try: + item1 = db_session.query(Collection).filter(Collection.id == id).first() + item2 = db_session.query(Collection).filter(Collection.order == order).first() + order1 = item1.order + # order2 = item2.order + id2 = item2.id + db_session.query(Collection).filter(Collection.id == id).update({Collection.order: order}) + db_session.query(Collection).filter(Collection.id == id2).update({Collection.order: order1}) + 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)