Browse Source

改变了初始化Collection的方式 使用uuid生成全局唯一id

master
邓淳远 4 years ago
parent
commit
3dc1eace88
2 changed files with 6 additions and 5 deletions
  1. +4
    -3
      APP/view/collection.py
  2. +2
    -2
      APP/view/model.py

+ 4
- 3
APP/view/collection.py View File

@ -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'] =

+ 2
- 2
APP/view/model.py View File

@ -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):

Loading…
Cancel
Save