Example #1
0
class HouseImage(BaseModel,db.Model):
    # 房屋图片
    __tablename__ = "ihome_house_image"
    id = db.Column(db.Integer,primary_key=True)
    # 房屋编号
    house_id = db.Column(db.Integer,db.ForeignKey('ihome_house.id'),nullable=True)
    url = db.Column(db.String(256),nullable=False) # 图片的路径
Example #2
0
class GoodsImage(BaseModel, db.Model):
    """商品图片"""
    __tablename__ = "goods_image"
    id = db.Column(db.Integer, primary_key=True)
    goods_id = db.Column(db.Integer, db.ForeignKey("goods.id"),
                         nullable=False)  # 商品id
    url = db.Column(db.String(255), nullable=False)  # 图片的路径
Example #3
0
class ReportedLoss(BaseModel, db.Model):
    '''报损失'''
    __tablename__ = "reportedloss"
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)  # id自增
    # create_time = db.Column(db.DATETIME, default=datetime.now)  # 创建时间
    goods_id = db.Column(db.Integer)  # 商品id
    inventory = db.Column(db.Integer)  # 库存id
Example #4
0
class Order(BaseModel, db.Model):

    __tablename__ = 'ihome_order'

    id = db.Column(db.Integer, primary_key=True)
    # 外键关联用户, 一个用户对应多个订单
    user_id = db.Column(db.Integer,
                        db.ForeignKey('ihome_user.id'),
                        nullable=False)
    # 一个房子对应多个订单
    house_id = db.Column(db.Integer,
                         db.ForeignKey('ihome_house.id'),
                         nullable=False)
    # 订单的创建时间
    begin_date = db.Column(db.DateTime, nullable=False)
    # 订单的结束时间
    end_date = db.Column(db.DateTime, nullable=False)
    # 订单生效的天数
    days = db.Column(db.Integer, nullable=False)
    # 房间的价格
    house_price = db.Column(db.Integer, nullable=False)
    # 房间的数量
    amount = db.Column(db.Integer, nullable=False)
    # 订单的状态,使用了枚举法, index 等于 true 意思是 默认开启了下标索引, WAIT_ACCEPT相当于0, 可以使用时可以用0代替
    status = db.Column(
        db.Enum(
            # 待接单
            'WAIT_ACCEPT',
            # 待支付
            'WAIT_PAYMENT',
            # 已支付
            'PAID',
            # 待评价
            'WAIT_COMMENT',
            # 已完成
            'COMPLETE',
            # 已取消
            'CANCELED',
            # 已拒单
            'REJECTED'),
        default='WAIT_ACCEPT',
        index=True)
    # 订单评价
    comment = db.Column(db.Text)

    # 把订单对象初始化如下的字典形式
    def to_dict(self):
        return {
            'order_id': self.id,
            'house_title': self.house.title,
            'image':
            self.house.index_image_url if self.house.index_image_url else '',
            'create_date': self.create_time.strftime('%Y-%m-%d'),
            'begin_date': self.begin_date.strftime('%Y-%m-%d'),
            'end_date': self.end_date.strftime('%Y-%m-%d'),
            'amount': self.amount,
            'days': self.days,
            'status': self.status,
            'comment': self.comment
        }
Example #5
0
class GoodsClassification(BaseModel, db.Model):
    '''商品分类'''
    __tablename__ = 'good_classification'
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)  # id自增
    c_title = db.Column(db.String(64), nullable=False)  # 标题
    parent_id = db.Column(db.INTEGER)
    # goods = db.relationship('Goods', backref='good_classification')  # 关联到商品
    goods = db.relationship("Goods", secondary=goods_goodsclassification)
Example #6
0
class Area(BaseModel, db.Model):
    # 区域
    __tablename__ = "ihome_area"
    id = db.Column(db.Integer, primary_key=True)  # 区域编号
    name = db.Column(db.String(32), nullable=False)  # 区域名称
    houses = db.relationship("House", backref="area")  # 区域的房屋

    def to_dict(self):
        return {'id': self.id, 'name': self.name}
Example #7
0
class Citys(BaseModel, db.Model):
    '''地区表'''
    __tablename__ = 'citys'
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)  # id自增
    province = db.Column(db.String(200))  # 城市
    parent_id = db.Column(db.Integer, nullable=True)

    areas = db.relationship('CustomerShippingAddress',
                            backref='city')  # 关联到客户收获地址
Example #8
0
class HouseImage(BaseModel, db.Model):
    """房屋图片"""

    __tablename__ = 'ihome_house_image'

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ihome_house.id"),
                         nullable=False)
    url = db.Column(db.String(256), nullable=False)
Example #9
0
class Area(BaseModel, db.Model):
    """城区"""

    __tablename__ = 'ihome_area'

    id = db.Column(db.INTEGER, primary_key=True)  # 区域编号
    name = db.Column(db.String(32), nullable=False)  # 区域名字
    houses = db.relationship('House', backref='area')  # 区域的房屋

    def to_dict(self):
        return {'id': self.id, 'name': self.name}
Example #10
0
class GoodsComments(BaseModel, db.Model):
    '''商品评价表'''
    __tablename__ = "goods_comments"
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer, db.ForeignKey("customer.id"))  # 客户id
    # order_status = db.Column(db.String(255), db.ForeignKey("order.status"))  # 订单状态
    evaluate = db.Column(db.String(255))  # 评价
    reply_id = db.Column(db.Integer, nullable=True)  # 回复id

    Order = db.relationship("Order", secondary=goodscomments_goods_order)
    Goods = db.relationship("Goods", secondary=goodscomments_goods_order)
Example #11
0
class HouseImage(BaseModel, db.Model):

    __tablename__ = 'ihome_house_image'

    id = db.Column(db.Integer, primary_key=True)
    # 外键关联房间的id
    house_id = db.Column(db.Integer,
                         db.ForeignKey('ihome_house.id'),
                         nullable=False)
    # 图片
    url = db.Column(db.String(256), nullable=False)
Example #12
0
class Facility(BaseModel, db.Model):
    # 设备信息,房屋规格等信息
    __tablename__ = "ihome_facility"
    id = db.Column(db.Integer, primary_key=True)  # 设施编号
    name = db.Column(db.String(32), nullable=False)  # 设施名称
    css = db.Column(db.String(30), nullable=True)  # 设施展示的图标

    def to_dict(self):
        return {'id': self.id, 'name': self.name, 'css': self.css}

    def to_house_dict(self):
        return {'id': self.id}
Example #13
0
class PublishLog(db.Model):
    __tablename__ = 'publish_log'
    id = db.Column(db.Integer,
                   nullable=False,
                   primary_key=True,
                   autoincrement=True)
    logger_date = db.Column(db.DateTime, nullable=False)
    logger_success = db.Column(db.Text)
    logger_error = db.Column(db.Text)
    server_id = db.Column(db.Integer, db.ForeignKey('servers.id'))

    def __repr__(self):
        return '<Logger id: %s date: %s>' % (self.id, self.logger_date)
Example #14
0
class BaseModel(object):
    create_time = db.Column(db.DATETIME, default=datetime.now())
    update_time = db.Column(db.DATETIME,
                            default=datetime.now(),
                            onupdate=datetime.now())

    def add_update(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delele(self)
        db.session.commit()
Example #15
0
class Course(db.Model):
    c_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    c_name = db.Column(db.String(10), unique=True)
    students = db.relationship(
        'Student',  # 关联模块
        secondary=sc,  # 中间表名称
        backref='cou'  # 反向身份引用,学生实例.cou --> 对应的课程信息
    )
    # 如果不写表名,则自动命名为模块名的小写(不行的!!)
    __tablename__ = 'course'

    def __init__(self, name):
        self.c_name = name
Example #16
0
class Area(BaseModel, db.Model):

    __tablename__ = 'ihome_area'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), nullable=False)
    houses = db.relationship('House', backref='area')

    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
        }
Example #17
0
class Facility(BaseModel, db.Model):
    """设备信息, 房屋规格等信息"""

    __tablename__ = 'ihome_facility'

    id = db.Column(db.INTEGER, primary_key=True)  # 设施编号
    name = db.Column(db.String(32), nullable=False)  # 设施名称
    css = db.Column(db.String(30), nullable=True)  # 设施展示的图标

    def to_dict(self):
        return {'id': self.id, 'name': self.name, 'css': self.css}

    def to_hosut_dict(self):
        return {'id': self.id}
Example #18
0
class Facility(BaseModel, db.Model):
    """设施信息,房间规格"""

    __tablename__ = 'ihome_facility'

    id = db.Column(db.Integer, primary_key=True)  # 设施编号
    name = db.Column(db.String(32), nullable=False)  # 设施名字
    css = db.Column(db.String(30), nullable=True)  # 设施名字

    def to_dict(self):
        return {'id': self.id, 'name': self.name, 'css': self.css}

    def to_house_dict(self):
        return {'id': self.id}
Example #19
0
class Facility(BaseModel, db.Model):

    __tablename__ = 'ihome_facility'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), nullable=False)
    css = db.Column(db.String(30), nullable=True)

    # 把对象初始化下面的字典模式
    def to_dict(self):
        return {'id': self.id, 'name': self.name, 'css': self.css}

    def to_house_dict(self):
        return {'id': self.id}
Example #20
0
class Grade(db.Model):  # 班级模型
    g_id = db.Column(db.Integer, primary_key=True,
                     autoincrement=True)  # 班级id  主键  自增
    g_name = db.Column(db.String(10), unique=True)  # 班级名称  独一无二
    g_desc = db.Column(db.String(100), nullable=True)  # 班级描述  可以为空
    g_create_time = db.Column(db.Date, default=datetime.now)  # 创建时间,默认为当前时间
    # Student:关联的模型名称  backref -- (关联模型实例.stu --> 对应的Grade实例)
    # lazy:懒加载  访问时(即 grade.students)才加载两个模型间的关系
    students = db.relationship('Student', backref='stu', lazy=True)
    __tablename__ = "grade"

    def __init__(self, name, desc):
        self.g_name = name
        self.g_desc = desc
Example #21
0
class HouseImage(BaseModel, db.Model):
    """房屋图片"""

    __tablename__ = 'ihome_house_image'

    id = db.Column(db.INTEGER, primary_key=True)
    # 房屋编号
    house_id = db.Column(db.INTEGER,
                         db.ForeignKey('ihome_house.id'),
                         nullable=False)
    url = db.Column(db.String(256), nullable=False)  # 图片路径

    def to_dict(self):

        return {'house_': self.house_id, 'url': self.url}
Example #22
0
class Grade(db.Model):

    g_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    g_name = db.Column(db.String(10), unique=True)
    g_desc = db.Column(db.String(100), nullable=True)
    g_time = db.Column(db.Date, default=datetime.now)
    # backref='stu' 是通过stu来找班级,即student.stu
    students = db.relationship('Student', backref='stu', lazy=True)

    __tablename__ = 'grade'

    def __init__(self, name, desc):

        self.g_name = name
        self.g_desc = desc
Example #23
0
class Student(db.Model):  # 学生模型
    s_id = db.Column(db.INTEGER, primary_key=True,
                     autoincrement=True)  # id 整型  主键  自增
    s_name = db.Column(db.String(20), unique=True)  # 姓名  字符串  不重复
    s_age = db.Column(db.INTEGER, default=10)  # 年龄 整型 默认10
    # 外键虽然不能像Django中的那样直接使用,但是不可或缺,否则会出现如下错误
    # NoForeignKeysError: Could not determine join condition between parent/child tables on relationship Grade.students
    # - there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey
    # or ForeignKeyConstraint, or specify a 'primaryjoin' expression.
    # 加unique=True 即为OneToOne
    s_g = db.Column(db.Integer, db.ForeignKey("grade.g_id"), nullable=True)
    __tablename__ = "student"

    def __init__(self, name, age):  # 初始化函数
        self.s_name = name
        self.s_age = age
Example #24
0
class Order(BaseModel, db.Model):
    '''

    '''
    __tablename__ = 'ihome_order'

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey('ihome_user.id'),
                        nullable=False)
    house_id = db.Column(db.Integer,
                         db.ForeignKey('ihome_house.id'),
                         nullable=False)
    begin_date = db.Column(db.DateTime, nullable=False)
    end_date = db.Column(db.DateTime, nullable=False)
    days = db.Column(db.Integer, nullable=False)
    house_price = db.Column(db.Integer, nullable=False)
    amount = db.Column(db.Integer, nullable=False)
    status = db.Column(
        db.Enum(
            'WAIT_ACCEPT',  # 待接单
            'WAIT_PAYMENT',  # 待支付
            'PAID',  # 已支付
            'WAIT_COMMENT',  # 待评价
            'COMPLETE',  # 已完成
            'CANCELED',  # 已取消
            'REJECTED'  # 已拒单
        ),
        default='WAIT_ACCEPT',
        index=True)
    comment = db.Column(db.Text)

    def to_dict(self):
        return {
            'order_id': self.id,
            'house_title': self.house.title,
            'image':
            self.house.index_image_url if self.house.index_image_url else '',
            'create_date': self.create_time.strftime('%Y-%m-%d'),
            'begin_date': self.begin_date.strftime('%Y-%m-%d'),
            'end_date': self.end_date.strftime('%Y-%m-%d'),
            'amount': self.amount,
            'days': self.days,
            'status': self.status,
            'comment': self.comment
        }
Example #25
0
class User(BaseModel, db.Model):

    __tablename__ = 'ihome_user'

    id = db.Column(db.Integer, primary_key=True)
    phone = db.Column(db.String(11), unique=True)
    pwd_hash = db.Column(db.String(200))
    name = db.Column(db.String(30), unique=True)
    avatar = db.Column(db.String(100))  # 头像
    id_name = db.Column(db.String(30))  # 实名认证姓名
    id_card = db.Column(db.String(18), unique=True)  # 实名认证身份证号码

    @property
    def password(self):
        """读取密码"""
        return ''

    @password.setter
    def password(self, pwd):
        """给密码加密存入数据库"""
        self.pwd_hash = generate_password_hash(pwd)

    def check_password(self, pwd):
        """校验密码"""
        return check_password_hash(self.pwd_hash, pwd)

    def to_basic_dict(self):
        """json格式返回用户信息"""
        return {
            'id': self.id,
            'name': self.name,
            'phone': self.phone,
            'avatar': self.avatar if self.avatar else ''
        }
Example #26
0
class User(BaseModel, db.Model):
    __tablename__ = "ihome_user"
    id = db.Column(db.INTEGER, primary_key=True)
    phone = db.Column(db.String(11), unique=True)
    pwd_hash = db.Column(db.String(200))  # 密码
    name = db.Column(db.String(30), unique=True)
    avatar = db.Column(db.String(100))  # 头像
    id_name = db.Column(db.String(30))  # 实名认证的姓名
    id_card = db.Column(db.String(18), unique=True)

    # houses = db.relationship('House',backref="user")
    # orders = db.relationship('Order',backref="user")

    @property
    def password(self):
        return ''  # 阻止访问密码

    @password.setter
    def password(self, pwd):  # 设置密码
        self.pwd_hash = generate_password_hash(pwd)  # 对密码进行加密

    # 校验密码
    def check_pwd(self, pwd):
        return check_password_hash(self.pwd_hash, pwd)

    def to_basic_dict(self):  # 将当前的self对象序列化
        return {
            'id': self.id,
            'avatar': self.avatar if self.avatar else '',
            'name': self.name,
            'phone': self.phone,
        }
Example #27
0
class User(BaseModel, db.Model):

    __tablename__ = 'ihome_user'
    id = db.Column(db.INTEGER, primary_key=True)
    phone = db.Column(db.String(11), unique=True)
    pwd_hash = db.Column(db.String(200))
    name = db.Column(db.String(30), unique=True)
    avatar = db.Column(db.String(100))  # 头像
    id_name = db.Column(db.String(30))  # 实名认证的姓名
    id_card = db.Column(db.String(18), unique=True)  # 实名认证身份证号码

    houses = db.relationship('House', backref='user')
    orders = db.relationship('Order', backref='user')

    # 读
    @property
    def password(self):
        return ''

    # 写
    @password.setter
    def password(self, pwd):
        self.pwd_hash = generate_password_hash(pwd)

    # 对比
    def check_pwd(self, pwd):
        return check_password_hash(self.pwd_hash, pwd)

    def to_basic_dict(self):
        return {
            'id': self.id,
            'avatar': self.avatar,
            'name': self.name,
            'phone': self.phone
        }
Example #28
0
class Order(BaseModel, db.Model):

    __tablename__ = "ihome_order"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ihome_user.id"),
                        nullable=False)
    house_id = db.Column(db.Integer,
                         db.ForeignKey('ihome_house.id'),
                         nullable=False)
    begin_date = db.Column(db.DATETIME, nullable=False)
    end_date = db.Column(db.DATETIME, nullable=False)
    days = db.Column(db.Integer, nullable=False)
    house_price = db.Column(db.Integer, nullable=False)
    amount = db.Column(db.Integer, nullable=False)  # 总的价格
    status = db.Column(
        db.Enum(
            "WAIT_ACCEPT",  # 待接单
            "WAIT_PAYMENT",  # 代付款
            "PAID",  # 已支付
            "WAIT_COMMENT",  # 待评价
            "COMPLETE",  # 已完成
            "CANCELED",  # 已取消
            "REJECTED"  # 已拒单
        ),
        default="WAIT_ACCEPT",
        index=True)
    comment = db.Column(db.Text)

    def to_dict(self):
        return {
            'order_id': self.id,
            'house_title': self.house.title,
            'image':
            self.house.index_image_url if self.house.index_image_url else "",
            'create_date': self.create_time.strftime('%Y-%m-%d'),
            'begin_date': self.begin_date.strftime('%Y-%m-%d'),
            'end_date': self.end_date.strftime('%Y-%m-%d'),
            'amount': self.amount,
            'days': self.days,
            'status': self.status,
            'comment': self.comment
        }
Example #29
0
class CustomerShippingAddress(BaseModel, db.Model):

    __tablename__ = 'customer_shipping_address'
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("customer.id"),
                        nullable=False)  # 客户编号
    area_id = db.Column(db.Integer, db.ForeignKey("citys.id"))  # 归属地编号
    name = db.Column(db.String(50))  # 收件人姓名
    tel = db.Column(db.String(50))  # 联系电话
    about_address = db.Column(db.String(255))  # 地址详情
    disabled = db.Column(db.Boolean, default=False)  # 是否默认地址
Example #30
0
class Inventory(BaseModel, db.Model):
    '''库存'''
    __tablename__ = "inventory"
    id = db.Column(db.INTEGER, primary_key=True, autoincrement=True)  # id自增
    goods_id = db.Column(db.Integer)  # 商品id
    order_id = db.Column(db.Integer)  # 订单id
    order_status = db.Column(db.String(255))  # 订单状态
    i_number = db.Column(db.Integer, default=0)  # 库存数量
    shape_code = db.Column(db.String(200))  # 条形码