class User_write_text(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) userid = db.Column(db.Integer) text = db.Column(db.Text) time = db.Column(db.String(30)) title = db.Column(db.String(30)) __tablename__ = 'user_write_text'
class Public_text(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) from_userid = db.Column(db.Integer) from_name = db.Column(db.String(30)) time = db.Column(db.String(30)) massage = db.Column(db.Text) __tablename__ = 'public_text'
class User_massage(db.Model): userid = db.Column(db.Integer, primary_key=True, autoincrement=True) real_name = db.Column(db.String(30)) sex = db.Column(db.String(10)) location = db.Column(db.String(50)) phone = db.Column(db.String(11)) email = db.Column(db.String(30)) __tablename__ = 'user_massage'
class User(db.Model, DBO): userid = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(77), nullable=False, unique=True) password = db.Column(db.String(77), nullable=False) # feature = ... 作为用户的订阅频道 # 表格更名 __tablename__ = 'user'
class User(db.Model): userid = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(77), nullable=False, unique=True) password = db.Column(db.String(77), nullable=False) # 表格更名 __tablename__ = 'user' # 初始化每个实例。(若在第6步导入DBO文件,可不用写以下初始化语句,DBO类方法中已封装。) def __init__(self, username, password): self.username = username self.password = password
class Student(db.Model, DBO): s_id = db.Column(db.Integer, primary_key=True) s_name = db.Column(db.String(100), nullable=False) s_age = db.Column(db.Integer, nullable=False) s_sex = db.Column(db.String(10), nullable=False) __tablename__ = 'student' # 创建班级对象 # Grade.add(g_name="zzpy180701", g_num=0) # 为班级分配学生 # Grade.query.get(1).update(stus=Student.query.get(101))
class News(db.Model, DBO): news_id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(255)) time = db.Column(db.String(64)) content = db.Column(db.String(255)) author = db.Column(db.String(255)) news_url = db.Column(db.String(255)) # pageSize = db.C # 外键先设置在这里 不一定需要用.连外键时出错 # user_id = db.Column(db.Integer, db.ForeignKey('user.userid')) __tablename__ = 'news'
class Image(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) url = db.Column(db.String(512)) # 数据库中的外键,表示ID来源于User.id # URL为什么不用粘贴网址?db.Datetime是自定义数据类型? # id是图片id,user_id是图片所属的人的id,外键链接到user.id这一列上 # news_id可能有问题 #news_id =db.Column(db.Integer, db.ForeignKey('news.news_id')) create_date = db.Column(db.DateTime) # comments = db.relationship('Comment') __table_args__ = {'extend_existing': True} __tablename__ = 'image' # 初始化函数 def __init__(self, url, user_id): self.url = url self.user_id = user_id self.create_date = datetime.now() #当前时间 def __repr__(self): return '<Image %d %s>' % (self.id, self.url)
class Grade(db.Model, DBO): g_id = db.Column(db.Integer, primary_key=True, autoincrement=True) g_name = db.Column(db.String(50), unique=True, nullable=False) g_num = db.Column(db.Integer, nullable=False) stus = db.relationship('Student', backref='gd', lazy='dynamic') __tablename__ = 'grade'
class User_tou(db.Model): userid = db.Column(db.Integer, primary_key=True, autoincrement=True) address = db.Column(db.String(70)) __tablename__ = 'user_tou'