class Question(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) created_at = db.Column(db.DateTime, default=datetime.now()) updated_at = db.Column(db.DateTime, default=datetime.now()) content = db.Column(db.String(8000)) status = db.Column(db.String(80)) img = db.Column(db.String(200)) view_count = db.Column(db.Integer, default=0) agree = db.Column(db.Integer, default=0) disagree = db.Column(db.Integer, default=0) comments = db.relationship('QuestionComment', backref='Question', lazy='dynamic') tags = db.relationship('QuestionTag', secondary="question_tag_mid", backref='Question', lazy='dynamic') fields = db.relationship('Field', secondary="question_field_mid", backref='Question', lazy='dynamic') user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<Project %r>' % self.name
class UserV(db.Model): __tablename__ = 'user_v' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) users = db.relationship('User', backref='UserV', lazy='dynamic') def __repr__(self): return '<UserV %r>' % self.name
class UserDegree(db.Model): __tablename__ = 'user_degree' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80)) users = db.relationship('User', backref='UserDegree', lazy='dynamic')
class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(80), unique=True) email = db.Column(db.String(80), unique=True) auth = db.Column(db.Integer) avartar = db.Column(db.String(120)) password = db.Column(db.String(120)) created_at = db.Column(db.DateTime, default=datetime.now()) work_id = db.Column(db.String(120)) mobile = db.Column(db.String(120), unique=True) content = db.Column(db.String(120)) level_id = db.Column(db.Integer, db.ForeignKey('user_level.id')) prestige_id = db.Column(db.Integer, db.ForeignKey('user_prestige.id')) v_id = db.Column(db.Integer, db.ForeignKey('user_v.id')) level = db.relationship('UserLevel') prestige = db.relationship('UserPrestige') v = db.relationship('UserV') posts = db.relationship('Post', backref='User', lazy='dynamic') post_comments = db.relationship('PostComment', backref='User', lazy='dynamic') projects = db.relationship('Project', backref='User', lazy='dynamic') project_comments = db.relationship('ProjectComment', backref='User', lazy='dynamic') questions = db.relationship('Question', backref='User', lazy='dynamic') question_comments = db.relationship('QuestionComment', backref='User', lazy='dynamic') degree_id = db.Column(db.Integer, db.ForeignKey('user_degree.id')) major_id = db.Column(db.Integer, db.ForeignKey('user_major.id')) degree = db.relationship('UserMajor') major = db.relationship('UserDegree') sended_msgs = db.relationship('Message', backref='from', lazy='dynamic', foreign_keys=Message.from_id) recived_msgs = db.relationship('Message', backref='to', lazy='dynamic', foreign_keys=Message.to_id) recived_notifications = db.relationship('Notification', secondary="notification_user_mid", backref='User', lazy='dynamic') def __repr__(self): return '<User %r>' % self.username