Пример #1
0
class User(db.Model):
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    username = db.Column(db.String(20), nullable=False, unique=False)
    password = db.Column(db.String(8), unique=True)
    phone = db.Column(db.String(11), unique=True)

    def __str__(self):
        return self.username
Пример #2
0
class Blog(db.Model):
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    title = db.Column(db.String(200), nullable=False, unique=False)
    content = db.Column(db.String(1000), unique=True)

    # phone = db.Column(db.String(11),unique=True)

    def __str__(self):
        return self.title
Пример #3
0
class Article(db.Model):
    __tablename__ = 'article'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(256), nullable=False)
    content = db.Column(db.Text, nullable=False)
    author = db.Column(db.String(100), nullable=False)
    image_url = db.Column(db.String(256))
    time = db.Column(db.Date, default=datetime.today())
    tag = db.Column(db.String(100), nullable=False)
Пример #4
0
class ProductCatagory(db.Model):
    self_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    parent_id = db.Column(db.Integer, nullable=False)
    type_name = db.Column(db.String(20), nullable=False)
    keywords = db.Column(db.String(20), nullable=False)
    description = db.Column(db.Text, nullable=True)
    product_sort = db.Column(db.Integer, nullable=True)
    visable = db.Column(db.Integer, nullable=False, default=1)
    dirPath = db.Column(db.String(80), nullable=False)
Пример #5
0
class ArticleType(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    type_name = db.Column(db.String(20), nullable=False)
    articles = db.relationship('Article', backref='type')

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

    def __str__(self):
        return self.type_name
Пример #6
0
class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(32), nullable=False)
    password = db.Column(db.String(101), nullable=False)
    phone = db.Column(db.String(11), nullable=False, unique=True)
    email = db.Column(db.String(30))
    icon = db.Column(db.String(100))
    is_delete = db.Column(db.Boolean, default=False)
    register_time = db.Column(db.DateTime, default=datetime.datetime.now)
    # 增加一个字段,不会出现在数据库中,relationship()是在view和template中体现价值的
    #                                      backref:反向引用,通过文章找user
    # lay决定了sqlalchemy什么时候从数据库中加载数据,dynamic在有多条数据的时候特别有用,不是直接加载这些数据
    # 默认是select
    articles = db.relationship('Article', backref='user')
    comments = db.relationship('Comment', backref='user')
    __table_args__ = {'extend_existing': True, 'mysql_charset': 'utf8'}

    def __str__(self):
        return self.username
Пример #7
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'))
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
0
class Goods(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    goods_name = db.Column(db.String(100), nullable=False)
    price = db.Column(db.Float, nullable=False)
    # 因为用户和商品是多对多关系,无法直接添加外键,所以要依赖第三张关系表来建立relationship,secondary=第三张表表名
    # relationship里的backref的值可以随便起,用来反向引用
    users = db.relationship('User',
                            backref='goods_list',
                            secondary='user_goods')

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

    def __str__(self):
        return self.goods_name
Пример #12
0
class Users(db.Model):
    def __init__(self, username, password, phone, email):
        self.username = username
        self.password = password
        self.phone = phone
        self.email = email

    uid = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), nullable=False)
    _password = db.Column(db.String(50), nullable=False)
    email = db.Column(db.String(50), nullable=True, unique=True)
    phone = db.Column(db.String(20), nullable=False, unique=True)

    @property
    def password(self):
        return self._password

    @password.setter
    def password(self, raw_password):
        self._password = generate_password_hash(raw_password)

    def check_password(self, raw_password):
        return check_password_hash(self.password, raw_password)
Пример #13
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
Пример #14
0
class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(100), nullable=False)
    role = db.Column(db.Integer, default=10)
Пример #15
0
class Message(db.Model):
    __tablename__ = 'message'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False)
    message = db.Column(db.Text)
    time = db.Column(db.Date, default=datetime.today())