时间:2021-07-01 10:21:17 帮助过:17人阅读
class NewsType(Base): __tablename__ = ‘newstype‘ nid = Column(Integer, primary_key=True, autoincrement=True) caption = Column(String(32))
class News(Base): __tablename__ = ‘news‘ nid = Column(Integer, primary_key=True, autoincrement=True) #建立外键---两个 user_info_id = Column(Integer, ForeignKey("userinfo.nid")) news_type_id = Column(Integer, ForeignKey("newstype.nid")) ctime = Column(TIMESTAMP) title = Column(String(32)) url = Column(String(128)) content = Column(String(150))
class Favor(Base): #点赞表 __tablename__ = ‘favor‘ nid = Column(Integer, primary_key=True, autoincrement=True) #点赞者id user_info_id = Column(Integer, ForeignKey("userinfo.nid")) #信息id news_id = Column(Integer, ForeignKey("news.nid")) ctime = Column(TIMESTAMP) #建立联合唯一索引 __table_args__ = ( UniqueConstraint(‘user_info_id‘, ‘news_id‘, name=‘uix_uid_nid‘), )
class Comment(Base): __tablename__ = ‘comment‘ nid = Column(Integer, primary_key=True, autoincrement=True) #评论者id user_info_id = Column(Integer, ForeignKey("userinfo.nid")) #评论的信息id news_id = Column(Integer, ForeignKey("news.nid")) #如果为None,就是评论文章,如果是数字就是回复某个人 reply_id = Column(Integer, ForeignKey("comment.nid"), nullable=True, default=None) #顶一下 up = Column(Integer) #踩一下 down = Column(Integer) #创建时间 ctime = Column(TIMESTAMP) #发表设备:手机,电脑,苹果.... device = Column(String(32)) #发表内容 content = Column(String(150))
抽屉之Tornado实战(2)--数据库表设计
标签:nullable 代码 table 不同的 class inf 方便 bsp 创建