Beispiel #1
0
class UserGoods(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    goods_id = db.Column(db.Integer, db.ForeignKey('goods.id'))
    number = db.Column(db.Integer, default=1)

    __table_args = {'extend_existing': True, 'mysql_charset': 'utf8'}
Beispiel #2
0
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'))
Beispiel #3
0
class Comment(db.Model):
    # 自定义表名
    __tablename__ = 'comment'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    comment = db.Column(db.String(255), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    article_id = db.Column(db.Integer, db.ForeignKey('article.id'))
    comment_date = db.Column(db.DateTime, default=datetime.datetime.now)

    __table_args = {'extend_existing': True, 'mysql_charset': 'utf8'}

    def __str__(self):
        return self.comment
Beispiel #4
0
class Article(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(50), nullable=False)
    content = db.Column(db.BLOB, nullable=False)
    publish_date = db.Column(db.DateTime, default=datetime.datetime.now)
    click_num = db.Column(db.Integer, default=0)
    save_num = db.Column(db.Integer, default=0)
    love_num = db.Column(db.Integer, default=0)
    # 建立外键关系
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    type_id = db.Column(db.Integer,
                        db.ForeignKey('article_type.id'),
                        nullable=False)
    comments = db.relationship('Comment', backref='article')

    __table_args = {'extend_existing': True, 'mysql_charset': 'utf-8'}

    def __str__(self):
        return self.title
Beispiel #5
0
class Question(db.Model):
    __tablename__ = 'question'
    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)
    # datetime.now()    获取服务器第一次运行的时间
    # datetime.now      获取记录创建时间
    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'))
Beispiel #6
0
class MessageBoard(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    content = db.Column(db.String(255), nullable=False)
    mdatetime = db.Column(db.DateTime, default=datetime.datetime.now)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User', backref='messages')

    __table__args = {'extend_existing': True, 'mysql_charset': 'utf-8'}

    def __str__(self):
        return self.content
Beispiel #7
0
class Photo(db.Model):
    __tablename__ = 'photo'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    photo_name = db.Column(db.String(32), nullable=False)
    photo_datetime = db.Column(db.DateTime, default=datetime.datetime.now)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)

    __table_args = {'extend_existing': True, 'mysql_charset': 'utf-8'}

    def __str(self):
        return self.photo_name
Beispiel #8
0
class AboutMe(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    content = db.Column(db.BLOB, nullable=False)
    pdatetime = db.Column(db.DateTime, default=datetime.datetime.now)
    # 与用户建立联系
    user_id = db.Column(
        db.Integer, db.ForeignKey('user.id'),
        unique=True)  # unique没有设置成True,查询出来的话会是一个列表,flask里的外键都是一对多
    user = db.relationship('User', backref='about')

    __table__args = {'extend_existing': True, 'mysql_charset': 'urf-8'}

    def __str__(self):
        return self.user