Browse Source

增加了collection删除功能 自动刷新order

master
邓淳远 4 years ago
parent
commit
01b9f7d952
1 changed files with 17 additions and 1 deletions
  1. +17
    -1
      APP/view/collection.py

+ 17
- 1
APP/view/collection.py View File

@ -4,6 +4,7 @@ import random
from APP.view.database import db_session from APP.view.database import db_session
from APP.view.model import Collection, UserLike from APP.view.model import Collection, UserLike
import uuid import uuid
bp_collection = Blueprint("collection", __name__, url_prefix="/collection") bp_collection = Blueprint("collection", __name__, url_prefix="/collection")
@ -16,7 +17,7 @@ def add_collection():
try: try:
count = Collection.query.count() count = Collection.query.count()
print(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.add(c)
db_session.commit() db_session.commit()
except BaseException as e: except BaseException as e:
@ -195,6 +196,21 @@ def delete():
""" """
id的collection 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'} ret = {'msg': 'succuss'}
return json_util.dumps(ret) return json_util.dumps(ret)

Loading…
Cancel
Save