class User(db.Model,UserMixin): __tablename__ = 'user' uid = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(30), nullable=False) password = db.Column(db.String(128), nullable=False) gender = db.Column(db.Integer) # 如果表的主键不是id,需要重写这个方法 def get_id(self): try: return text_type(self.uid) # 返回主键 except AttributeError: raise NotImplementedError('No `id` attribute - override `get_id`')
class Article(db.Model): aid = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(100), nullable=True) content = db.Column(db.String(10000)) create_time = db.Column(db.DateTime, default=datetime.now) cid = db.Column(db.Integer, db.ForeignKey("category.cid", ondelete="CASCADE")) hits = db.Column(db.Integer, default=0) replies = db.Column(db.Integer, default=0) picture = db.Column(db.String(300)) __tablename__ = 'article'
class User(db.Model, UserMixin): uid = db.Column(db.Integer, primary_key=True, autoincrement=True) username = db.Column(db.String(30), nullable=False, unique=True) password = db.Column(db.String(128), nullable=False) phone = db.Column(db.String(11)) email = db.Column(db.String(200)) portrait = db.Column(db.String(300)) regtime = db.Column(db.DateTime) isforbid = db.Column(db.Boolean, default=False) __tablename__ = 'user' # 如果表的主键不是id,需要重写这个方法 def get_id(self): try: return text_type(self.uid) # 返回主键 except AttributeError: raise NotImplementedError('No `id` attribute - override `get_id`')
class Mark(db.Model): mid = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.String(1000)) create_time = db.Column(db.DateTime) uid = db.Column(db.Integer, db.ForeignKey('user.uid'))
class Tag(db.Model): tid = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(30), nullable=True) aid = db.Column(db.Integer, db.ForeignKey("article.aid"))
class Category(db.Model): cid = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(100), nullable=False, unique=True) num = db.Column(db.Integer, default=0) __tablename__ = "category"