class Message(db.Model): __tablename__ = 'message' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) content_time = db.Column(db.DateTime, default=datetime.datetime.now) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('messages'))
class Type(db.Model): __tablename__ = 'type' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(50), nullable=False) description = db.Column(db.Text, nullable=False) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('types'))
class Articles(db.Model): __tablename__ = 'articles' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) create_time = db.Column(db.Date, default=time.strftime('%Y-%m-%d', time.localtime(time.time()))) tag_id = db.Column(db.Integer, db.ForeignKey('tags.id')) tag = db.relationship('Tags', backref=db.backref('articles')) __mapper_args__ = {'order_by': create_time.desc()}
class Commten(db.Model): __tablename__ = 'comment' id = db.Column(db.Integer, primary_key=True, autoincrement=True) content = db.Column(db.Text, nullable=False) content_time = db.Column(db.DateTime, default=datetime.datetime.now) article_id = db.Column(db.Integer, db.ForeignKey('article.id')) article = db.relationship('Article', backref=db.backref('comments', order_by=content_time.desc())) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('comments'))
class User(db.Model): __tablename__ = 'user' id = db.Column(db.Integer, autoincrement=True, primary_key=True) phone = db.Column(db.String(11), nullable=False) username = db.Column(db.String(50), nullable=False) password = db.Column(db.String(100), nullable=False) def __init__(self, *args, **kwargs): phone = kwargs.get('phone') username = kwargs.get('username') password = kwargs.get('password') self.phone = phone self.username = username self.password = generate_password_hash(password) def check(self, old_pwd): result = check_password_hash(self.password, old_pwd) return result
class Article(db.Model): __tablename__ = 'article' id = db.Column(db.Integer, primary_key=True, autoincrement=True) title = db.Column(db.String(50), nullable=False) content = db.Column(db.Text, nullable=False) description = db.Column(db.Text, nullable=False) zan_num = db.Column(db.Integer, default=0, nullable=False) up_time = db.Column(db.DateTime, default=datetime.datetime.now) type_id = db.Column(db.Integer, db.ForeignKey('type.id')) type = db.relationship('Type', backref=db.backref('articles', order_by=up_time.desc())) author_id = db.Column(db.Integer, db.ForeignKey('user.id')) author = db.relationship('User', backref=db.backref('articles'))
class User(db.Model): __tablename__ = 'user' id = db.Column(db.String(100), primary_key=True, default=shortuuid.uuid) name = db.Column(db.String(50), nullable=False) password = db.Column(db.String(100), nullable=False)
class Tags(db.Model): __tablename__ = 'tags' id = db.Column(db.Integer, primary_key=True, autoincrement=True) tagname = db.Column(db.String(100), nullable=False)