-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
52 lines (45 loc) · 1.91 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#coding=utf-8
from flask import Flask
from flask_login import UserMixin
from sqlalchemy import text,DateTime,Numeric
from flask_sqlalchemy import SQLAlchemy
import config
app = Flask(__name__)
app.config.from_object(config)
db = SQLAlchemy(app)
Base = db.Model
metadata = Base.metadata
def to_dict(self):
"""
model 对象转 字典
model_obj.to_dict()
"""
return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}
Base.to_dict = to_dict
class Admin(Base,UserMixin):
__tablename__ = 'admins'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
email = db.Column(db.String(320), unique=True)
password = db.Column(db.String(32), nullable=False)
class User(Base):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80), unique=True)
id_card = db.Column(db.Integer, nullable=False)
phone = db.Column(db.String(20), unique=True,nullable=False)
password = db.Column(db.String(32))
amount = db.Column(Numeric(10, 2), nullable=False, server_default=text("'0.00'"))
vip = db.Column(db.Integer, nullable=True, server_default=text("'0'"))
dele = db.Column(db.String(80),server_default=text("'0'"))
note = db.Column(db.String(200), nullable=True)
create_time = db.Column(DateTime, nullable=True, server_default=text("CURRENT_TIMESTAMP"))
class Wallet(Base):
__tablename__ = 'wallet'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80))
id_card = db.Column(db.Integer, nullable=False)
amount = db.Column(Numeric(10, 2), nullable=False, server_default=text("'0.00'"))
vip = db.Column(db.Integer, nullable=True, server_default=text("'0'"))
wallet_type = db.Column(db.Integer, nullable=True, server_default=text("'0'"))
create_time = db.Column(DateTime, nullable=True, server_default=text("CURRENT_TIMESTAMP"))