class ReportP(db.Model): __tablename__ = 'reports_p' id = db.Column(db.Integer, autoincrement=True, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) post_id = db.Column(db.Integer, db.ForeignKey('posts.id'), nullable=False) handle = db.Column(db.Integer, nullable=False, default=0) report_time = db.Column(db.DateTime, nullable=False, default=datetime.now) handle_time = db.Column(db.DateTime) user = db.relationship('User', backref=db.backref('reports_p')) article = db.relationship('Post', backref=db.backref('reported'))
class History(db.Model): __tablename__ = 'history' id = db.Column(db.Integer, primary_key=True, autoincrement=True) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) query_time = db.Column(db.DateTime, default=datetime.now) question = db.relationship('Question', backref=db.backref('historys', order_by=id.desc())) author = db.relationship('User', backref=db.backref('historys')) answer = db.Column(db.String(100), nullable=False)
class Answer(db.Model): __tablename__ = 'answer' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('answers')) question = db.relationship('Question', backref=db.backref('answers', order_by=id.desc()))
class Answer(db.Model): __tablename__ = 'answer' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) #负号是代表倒序, question = db.relationship('Question', backref=db.backref('answers', order_by=('-create_time'))) author = db.relationship('User', backref=db.backref('answers'))
class Present(db.Model): __tablename__ = 'present' id = db.Column(db.Integer, primary_key=True, autoincrement=True) # 引入外键task.id task_id = db.Column(db.Integer, db.ForeignKey('task.id')) # 引入外键user.id user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # 学生-作业(提交)一对多关系 user = db.relationship('User', backref=db.backref('presents')) # 作业发布-作业提交一对多关系 task = db.relationship('Task', backref=db.backref('presents'))
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) blog_id = db.Column(db.Integer, db.ForeignKey('blog.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) create_time = db.Column(db.DateTime, default=datetime.now) blog = db.relationship('Blog', backref=db.backref('comments', order_by=id.desc())) author = db.relationship('User', backref=db.backref('comments'))
class answer(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text) create_time = db.Column(db.DateTime, default=datetime.now) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) question = db.relationship('question', backref=db.backref('answer')) # question = db.relationship('question', backref=db.backref('answer'), order_by=id.desc()) author = db.relationship('user', backref=db.backref('answers'))
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('comments')) photo_id = db.Column(db.Integer, db.ForeignKey('photo.id')) photo = db.relationship('Photo', backref=db.backref('comments')) del_sign = db.Column(db.String(1))
class Cart(db.Model): # 购物车模型 __tablename__ = 'carts' id = db.Column(db.Integer, primary_key=True, autoincrement=True, index=True) userId = db.Column(db.Integer, db.ForeignKey('users.id')) productId = db.Column(db.Integer, db.ForeignKey('products.id')) quantity = db.Column(db.Integer, nullable=False) checked = db.Column(db.Integer, nullable=False) # 是否选择 1-勾选 0-未勾选 createTime = db.Column(db.DateTime, nullable=False) updateTime = db.Column(db.DateTime, nullable=True) user = db.relationship('User', backref=db.backref('myCart')) product = db.relationship('Product', backref=db.backref('products'))
class AnswerModel(db.Model): __tablename__ = 'answer' id = db.Column(db.Integer,primary_key=True,autoincrement=True) content = db.Column(db.Text,nullable=False) creat_time = db.Column(db.DateTime,default=datetime.now) author_id = db.Column(db.Integer,db.ForeignKey('user.id')) upload_id = db.Column(db.Integer,db.ForeignKey('uploads.id')) author =db.relationship('UserModel',backref=db.backref('answers')) # 通过author可以知道评论人的ID,通过answers可以知道这个id发过的评论 upload = db.relationship('UploadModel',backref=db.backref('answers'))
class Answer(db.Model): __tablename__ = "answer" id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) question_id = db.Column(db.Integer, db.ForeignKey("question.id")) author_id = db.Column(db.Integer, db.ForeignKey("user.id")) question = db.relationship("Question", backref=db.backref("answers"), order_by=id.desc()) author = db.relationship("User", backref=db.backref("answers"))
class Comment(db.Model): __tablename__ = "comment" id = db.Column(db.Integer,primary_key=True,autoincrement=True) content = db.Column(db.Text,nullable=False) create_time = db.Column(db.DateTime,default=datetime.now) is_ban = db.Column(db.Boolean,nullable=False,default=True) user_id = db.Column(db.Integer,db.ForeignKey("user.id")) question_id = db.Column(db.Integer,db.ForeignKey("question.id")) user = db.relationship("User",backref=db.backref("users")) question = db.relationship("Question",backref=db.backref("questions"))
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) comment = db.Column(db.Text(), nullable=False) question_id = db.Column(db.Integer, db.ForeignKey('question.id')) comment_author_id = db.Column(db.Integer, db.ForeignKey('user.id')) create_time = db.Column(db.DateTime, default=datetime.now) question = db.relationship( 'Question', backref=db.backref('question')) #, backref=db('question')) comment_author = db.relationship('User', backref=db.backref('question'))
class Comment(db.Model): """用户评论表模型""" __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) article_id = db.Column(db.Integer, db.ForeignKey('article.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) article = db.relationship('Article', backref=db.backref('comments')) author = db.relationship('User', backref=db.backref('comments'))
class Comment(db.Model): __tablename = 'Comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) comment_time = db.Column(db.DateTime, default=datetime.now) upload_id = db.Column(db.Integer, db.ForeignKey('Uploader.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) file_list = db.relationship('Uploader', backref=db.backref('file_list', order_by=id.desc())) author = db.relationship('User', backref=db.backref('author'))
class Message(db.Model): __tablename__ = 'message' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) # now()获取的是服务器第一次运行的时间 传递的是结果 # now 获取的是 每次创建模型的时间 传递的是方法 create_time = db.Column(db.DateTime, default=datetime.now) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) note_id = db.Column(db.Integer, db.ForeignKey('note.id')) # 该提问的作者 反向是该作者的所有提问 user = db.relationship('User', backref=db.backref('messages', order_by=(id.desc(), create_time.desc()))) note = db.relationship('Note', backref=db.backref('messages', order_by=(id.desc(), create_time.desc())))
class CommentStarModel(db.Model): __tablename__ = 'comment_star' id = db.Column(db.Integer, primary_key=True, autoincrement=True) create_time = db.Column(db.DateTime, default=datetime.now) author_id = db.Column(db.String(100), db.ForeignKey('front_user.id')) comment_id = db.Column(db.Integer, db.ForeignKey('comment.id')) author = db.relationship('FrontUser', backref=db.backref('comment_stars', cascade='all')) comment = db.relationship('CommentModel', backref=db.backref('stars', cascade='all'))
class Answer(db.Model): __tablename__ = 'answer' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) ask_id = db.Column(db.Integer, db.ForeignKey('ask.id')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) # Ask.create_time.desc()代表的是从大到小排序,去掉.desc(),默认从小到大排序 # order_by=id.desc()代表的按照id从大到小排序,不写这个order_by参数,默认从小到大排序 ask = db.relationship('Ask', backref=db.backref('answers', order_by=id.desc())) author = db.relationship('User', backref=db.backref('answers'))
class Export_Customs_Declaration(Customs_Declaration_Base, db.Model): __tablename__ = 'export_customs_declaration' export_port = db.Column(db.String(100)) export_date = db.Column(db.Date) destination_country = db.Column(db.String(100)) destination_port = db.Column(db.String(100)) goods_origin_place = db.Column(db.String(100)) manufacturer = db.Column(db.String(100)) settlement_mode_id = db.Column(db.Integer, db.ForeignKey('settlement_mode.id')) agreement_id = db.Column(db.Integer, db.ForeignKey('export_proxy_agreement.id')) operator_id = db.Column(db.Integer, db.ForeignKey('employee.id')) status_id = db.Column(db.Integer, db.ForeignKey('declaration_status.id')) transport_mode_id = db.Column(db.Integer, db.ForeignKey('transport_mode.id')) trade_mode_id = db.Column(db.Integer, db.ForeignKey('trade_mode.id')) transaction_mode_id = db.Column(db.Integer, db.ForeignKey('transaction_mode.id')) tax_mode_id = db.Column(db.Integer, db.ForeignKey('tax_mode.id')) customs_company_id = db.Column(db.Integer, db.ForeignKey('company.id')) business_company_id = db.Column(db.Integer, db.ForeignKey('company.id')) settlement_mode = db.relationship('Settlement_Mode', backref='export_declarations') agreement = db.relationship('Export_Proxy_Agreement', uselist=False) operator = db.relationship('Employee', backref='export_declarations') status = db.relationship('Declaration_Status', backref='export_declarations') transport_mode = db.relationship('Transport_Mode', backref='export_declarations') trade_mode = db.relationship('Trade_Mode', backref='export_declarations') transaction_mode = db.relationship('Transaction_Mode', backref='export_declarations') tax_mode = db.relationship('Tax_Mode', backref='export_declarations') customs_company = db.relationship('Company', foreign_keys=[customs_company_id], backref=db.backref( 'customs_export_declarations', lazy='dynamic')) business_company = db.relationship('Company', foreign_keys=[business_company_id], backref=db.backref( 'business_export_declarations', lazy='dynamic'))
class Theme(db.Model): __tablename__ = 'theme' id = db.Column(db.INTEGER, primary_key=True, autoincrement=True) #帖子编号 title = db.Column(db.String(100), nullable=False) #帖子标题 content = db.Column(db.Text, nullable=False) #帖子内容 answer_num = db.Column(db.INTEGER, default=0) #回复的评论数目 create_time = db.Column(db.DateTime, default=datetime.now) # 发帖时间 plate_id = db.Column(db.INTEGER, db.ForeignKey('plate.id')) #所属板块编号 author_id = db.Column(db.INTEGER, db.ForeignKey('user.id')) #发帖用户编号 plate = db.relationship( 'Plate', backref=db.backref('themes')) #帖子与板块建立连接(通过帖子访问所属板块,通过板块得到其中的帖子) author = db.relationship('User', backref=db.backref('themes')) #帖子与发帖人建立连接
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.UnicodeText, nullable=False) create_time = db.Column(db.DateTime, default=datetime.utcnow) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) answer_id = db.Column(db.Integer, db.ForeignKey('answer.id')) answer = db.relationship('Answer', backref=db.backref('comments', lazy='dynamic')) author = db.relationship('User', backref=db.backref('comments', lazy='dynamic')) def __repr__(self): return '<Comment %r>' % self.content
class Good(db.Model): __tablename__ = 'good' id = db.Column(db.BigInteger, primary_key=True, autoincrement=True) article_id = db.Column(db.BigInteger, db.ForeignKey('article.id'), nullable=False) user_id = db.Column(db.BigInteger, db.ForeignKey('user.id'), nullable=False) article = db.relationship('Article', backref=db.backref('goods')) user = db.relationship('User', backref=db.backref('goods')) __table_args__ = (db.UniqueConstraint('article_id', 'user_id', name='unique_article_user'), )
class Answer(db.Model): __tablename__ = 'answer' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) question_id = db.Column(db.Integer, db.ForeignKey('question.id', ondelete='CASCADE')) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) create_time = db.Column(db.DateTime, default=datetime.now) report_total = db.Column(db.Integer, nullable=True) report_reasons_and_times = db.Column(db.String(100), nullable=True) question = db.relationship('Question', backref=db.backref('answers', order_by=id.desc())) author = db.relationship('User', backref=db.backref('answers'))
class Comment(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) createTime = db.Column(db.DateTime, default=datetime.now()) viewCount = db.Column(db.Integer) likeNumber = db.Column(db.Integer) unlikeNumber = db.Column(db.Integer) article_id = db.Column(db.Integer, db.ForeignKey('article.id')) author_id = db.Column(db.String(100), db.ForeignKey('user.id')) article = db.relationship('Article', backref=db.backref('comments')) author = db.relationship('User', backref=db.backref('comments'))
class Import_Customs_Declaration(Customs_Declaration_Base, db.Model): __tablename__ = 'import_customs_declaration' import_port = db.Column(db.String(100)) import_date = db.Column(db.Date) tax_rate = db.Column(db.String(100)) departure_country = db.Column(db.String(100)) loading_port = db.Column(db.String(100)) domestic_destination = db.Column(db.String(100)) agreement_id = db.Column(db.Integer, db.ForeignKey('import_proxy_agreement.id'), unique=True) operator_id = db.Column(db.Integer, db.ForeignKey('employee.id')) status_id = db.Column(db.Integer, db.ForeignKey('declaration_status.id')) transport_mode_id = db.Column(db.Integer, db.ForeignKey('transport_mode.id')) trade_mode_id = db.Column(db.Integer, db.ForeignKey('trade_mode.id')) transaction_mode_id = db.Column(db.Integer, db.ForeignKey('transaction_mode.id')) tax_mode_id = db.Column(db.Integer, db.ForeignKey('tax_mode.id')) use_id = db.Column(db.Integer, db.ForeignKey('use.id')) customs_company_id = db.Column(db.Integer, db.ForeignKey('company.id')) business_company_id = db.Column(db.Integer, db.ForeignKey('company.id')) agreement = db.relationship('Import_Proxy_Agreement', uselist=False) operator = db.relationship('Employee', backref='import_declarations') status = db.relationship('Declaration_Status', backref='import_declarations') transport_mode = db.relationship('Transport_Mode', backref='import_declarations') trade_mode = db.relationship('Trade_Mode', backref='import_declarations') transaction_mode = db.relationship('Transaction_Mode', backref='import_declarations') tax_mode = db.relationship('Tax_Mode', backref='import_declarations') use = db.relationship('Use', backref='import_declarations') customs_company = db.relationship('Company', foreign_keys=[customs_company_id], backref=db.backref( 'customs_import_declarations', lazy='dynamic')) business_company = db.relationship('Company', foreign_keys=[business_company_id], backref=db.backref( 'business_import_declarations', lazy='dynamic'))
class PostModel(db.Model): __tablename__ = 'post' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.DateTime, default=datetime.now) update_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now) read_count = db.Column(db.Integer, default=0) is_removed = db.Column(db.Boolean, default=False) board_id = db.Column(db.Integer, db.ForeignKey('board.id')) author_id = db.Column(db.String(100), db.ForeignKey('front_user.id')) highlight_id = db.Column(db.Integer, db.ForeignKey('highlight_post.id')) #lazy默认为select,它的意义等同于原来的用法, # 如果想要在模板中使用filter方法,就要将它改为dynamic,可以将它变为一个query对象,可以使用filter方法 board = db.relationship('BoardModel', backref=db.backref('posts', lazy='dynamic')) author = db.relationship('FrontUser', backref='posts') # 一对一的关系,使用uselist=False highlight = db.relationship('HighlightPostModel', backref='post', uselist=False) def __init__(self, title, content, author, board): self.title = title self.content = content self.author = author self.board = board
class Friend(db.Model): __tablename__ = 'friend' id = db.Column(db.Integer, primary_key=True, autoincrement=True) friend_id = db.Column(db.Integer) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('friend'))
class Hobby(db.Model): __tablename__ = 'hobby' id = db.Column(db.Integer, primary_key=True, autoincrement=True) hobby = db.Column(db.String(500), nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) user = db.relationship('User', backref=db.backref('hobby_model'))
class Post(db.Model): __tablename__ = "post" id = db.Column(db.String(30), primary_key=True, default=shortuuid.uuid) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) img_link = db.Column(db.String(100), nullable=False) view = db.Column(db.Integer, default=0) star = db.Column(db.Integer, default=0) post_date = db.Column(db.Date, default=date.today()) author_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) cate_id = db.Column(db.Integer, db.ForeignKey("child_cate.id"), nullable=False) category = db.relationship("ChildCategory", backref=db.backref("posts")) author = db.relationship("User", backref=db.backref("posts"))
class ChildCategory(db.Model): __tablename__ = "child_cate" id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(10), nullable=False) parent_id = db.Column(db.Integer, db.ForeignKey("parent_cate.id")) parent = db.relationship("ParentCategory", backref=db.backref("childs"))