#!/usr/bin/env python from exts import db from datetime import datetime class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer,primary_key = True ,autoincrement = True ) username = db.Column(db.String( 50 ),nullable = False ) telephone = db.Column(db.String( 11 ),nullable = False ) password = db.Column(db.String( 100 ), nullable = False ) class Questions(db.Model): __tablename__ = 'questions' 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) author_id = db.Column(db.Integer,db.ForeignKey( 'user.id' )) author = db.relationship( 'User' ,backref = db.backref( 'questions' )) 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( 'questions.id' )) author_id = db.Column(db.Integer,db.ForeignKey( 'user.id' )) question = db.relationship( 'Questions' ,backref = db.backref( 'answers' )) author = db.relationship( 'User' ,backref = db.backref( 'answers' )) |