From 3dc1eace88b9348ca50e90a20bdc511594104972 Mon Sep 17 00:00:00 2001 From: CharlesDDDD <10185101155@stu.ecnu.edu.cn> Date: Mon, 11 Jan 2021 21:31:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=8F=98=E4=BA=86=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96Collection=E7=9A=84=E6=96=B9=E5=BC=8F=20=E4=BD=BF?= =?UTF-8?q?=E7=94=A8uuid=E7=94=9F=E6=88=90=E5=85=A8=E5=B1=80=E5=94=AF?= =?UTF-8?q?=E4=B8=80id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APP/view/collection.py | 7 ++++--- APP/view/model.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/APP/view/collection.py b/APP/view/collection.py index ad16235..25785c3 100644 --- a/APP/view/collection.py +++ b/APP/view/collection.py @@ -3,7 +3,7 @@ from bson import json_util 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") @@ -12,10 +12,11 @@ def add_collection(): name = request.form.get('name') tag = request.form.get('tag', None) phonenum = request.form.get('phonenum') + id = str(uuid.uuid1()) try: count = Collection.query.count() print(count) - c = Collection(id=count, name=name, tag=tag, phonenum=phonenum) + c = Collection(id=id, name=name, tag=tag, phonenum=phonenum,order=count) db_session.add(c) db_session.commit() except BaseException as e: @@ -23,7 +24,7 @@ def add_collection(): ret = {'msg': 'failed!', 'name': name} return json_util.dumps(ret) - ret = {'msg': 'succuss', 'name': name, 'id': str(count + 1)} + ret = {'msg': 'succuss', 'name': name, 'id': id} """; 插入最末尾 ret['id'] = diff --git a/APP/view/model.py b/APP/view/model.py index dee05dc..b147c78 100644 --- a/APP/view/model.py +++ b/APP/view/model.py @@ -23,13 +23,13 @@ class Collection(Base): like = Column(Integer) order =Column(Integer) - def __init__(self, id=None, name=None, tag=None, phonenum=None, like=0): + def __init__(self, id=None, name=None, tag=None, phonenum=None, like=0,order=None): self.id = id self.name = name self.tag = tag self.phonenum = phonenum self.like = like - self.order = id + self.order = order class Block(Base):