예제 #1
0
class BaseModel:

    id = db.Column(db.Integer, primary_key=True)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now())
    update_time = db.Column(db.DateTime,
                            default=datetime.datetime.now(),
                            onupdate=datetime.datetime.now())
예제 #2
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)  # 记录的更新时间
예제 #3
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)
예제 #4
0
class Area(BaseModel, db.Model):
    """城区"""
    __tablename__ = 'ih_area_info'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(32), nullable=False)
    house = db.relationship("House", backref="area")
예제 #5
0
class HouseFacility(db.Model):
    __tablename__ = "t_house_facility"
    __table_args__ = {"useexisting": True}

    id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer)
    facility_id = db.Column(db.Integer)
예제 #6
0
class Facility(db.Model):
    __tablename__ = "t_facility"
    __table_args__ = {"useexisting": True}

    facility_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    icon = db.Column(db.String)
class HouseImage(BaseModel):

    __tablename__ = "ihome_python_house_image"

    id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer, db.ForeignKey("ihome_python_house_info.id"), nullable=False)  # 房屋编号
    url = db.Column(db.String(256), nullable=False)  # 图片的路径
예제 #8
0
class Facility(BaseModel, db.Model):
    """设施信息"""

    __tablename__ = "ih_facility_info"

    id = db.Column(db.Integer, primary_key=True)  # 设施编号
    name = db.Column(db.String(32), nullable=False)  # 设施名字
예제 #9
0
class HouseImage(BaseModel,db.Model):
    """房屋图片"""
    __tablename__ = "i_house_image"

    id = db.Column(db.Integer,primary_key=True)
    house_id = db.Column(db.Integer,db.ForeignKey("i_house.id"),nullable=False) # 房屋编码
    url = db.Column(db.String(256),nullable=False) # 图片的路径
예제 #10
0
class Order(BaseModel, db.Model):
    """订单"""

    __tablename__ = "ih_order_info"

    id = db.Column(db.Integer, primary_key=True)  # 订单编号
    user_id = db.Column(db.Integer, db.ForeignKey("ih_user_profile.id"), nullable=False)  # 下订单的用户编号
    house_id = db.Column(db.Integer, db.ForeignKey("ih_house_info.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)  # 订单的评论信息或者拒单原因
예제 #11
0
class Order(BaseModel, db.Model):
    """订单详情模型类"""
    __tablename__ = "ih_order_info"

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ih_house_info.id"),
                         nullable=False)

    begin_date = db.Column(db.DateTime, nullable=False)
    end_data = 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)  # 订单评论信息或者拒单原因
class Area(BaseModel):

    __tablename = 'ihome_python_area_info'

    id = db.Column(db.Integer, primary_key=True)  # 区域编号
    name = db.Column(db.String(32), nullable=False)  # 区域名字
    houses = db.relationship('House', backref='area')
예제 #13
0
class Order(BaseModel, db.Model):
    """订单"""

    __tablename__ = "ih_order_info"

    id = db.Column(db.Integer, primary_key=True)  # 订单编号

    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),
                        nullable=False)  # 下订单的用户编号
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ih_house_info.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):
        """将订单信息转换为字典数据"""
        order_dict = {
            "order_id":
            self.id,
            "title":
            self.house.title,
            "img_url":
            constants.QINIU_URL_DOMAIN +
            self.house.index_image_url if self.house.index_image_url else "",
            "start_date":
            self.begin_date.strftime("%Y-%m-%d"),
            "end_date":
            self.end_date.strftime("%Y-%m-%d"),
            "ctime":
            self.create_time.strftime("%Y-%m-%d %H:%M:%S"),
            "days":
            self.days,
            "amount":
            self.amount,
            "status":
            self.status,
            "comment":
            self.comment if self.comment else ""
        }
        return order_dict
예제 #14
0
class HouseImg(db.Model):
    """房屋类型"""
    __tablename__ = "t_house_image"
    __table_args__ = {"useexisting": True}

    image_id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer)
    url = db.Column(db.String(255))
예제 #15
0
class Tag(db.Model):
    """房屋类型"""
    __tablename__ = "t_house_tag"
    __table_args__ = {"useexisting": True}

    tag_id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer)
    content = db.Column(db.String(11))
예제 #16
0
class HouseImage(BaseModel, db.Model):
    """房屋图片模型类"""
    __tablename__ = "ih_house_image"

    id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer,
                         db.ForeignKey("ih_house_info.id"),
                         nullable=False)
    url = db.Column(db.String(256), nullable=False)  # 所有图片路径地址
예제 #17
0
class Area(BaseModel, db.Model):
    '''城区'''

    __tablename__ = "ih_area_info"

    id = db.Column(db.Integer, primary_key=True)  #区域编号
    name = db.Column(db.String(32), nullable=False)  #区域名字
    # houses=db.relationship
    """
예제 #18
0
class Area(BaseModel, db.Model):
    """城区"""
    __tablename__ = "ih_area_info"
    area_id = db.Column(db.Integer, primary_key=True)  # 区域编号
    area_name = db.Column(db.String(32), nullable=False)  # 区域名字
    houses = db.relationship("House", backref="area")  # 区域的房屋

    # 将对象转换为字典
    def to_dic(self):
        dic = {"id": self.area_id, "name": self.area_name}
        return dic
예제 #19
0
class Area(BaseModel, db.Model):

    __tablename__ = 'ihome_python_area_info'

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

    def to_dict(self):
        d = {'aid': self.id, 'aname': self.name}
        return d
예제 #20
0
class Area(BaseModel, db.Model):
    """城区"""

    __tablename__ = "ih_area_info"

    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 {"aid": self.id, "aname": self.name}
예제 #21
0
파일: models.py 프로젝트: Samurai-XHe/ihome
class Area(BaseModel, db.Model):
    """城区"""

    __tablename__ = 'ih_area_info'

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

    def to_dict(self):
        area_dict = {'aid': self.id, 'aname': self.name}
        return area_dict
예제 #22
0
class Area(BaseModel, db.Model):
    """城区模型类"""
    __tablename__ = "ih_area_info"

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

    def to_dict(self):
        """将对象转换为字典"""
        d = {"aid": self.id, "aname": self.name}
        return d
예제 #23
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.delete(self)
        db.session.commit()
예제 #24
0
class HouseImage(db.Model):
    __tablename__ = __ = "t_house_image"
    __table_args__ = {"useexisting": True}

    image_id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer)
    url = db.Column(db.String)

    def to_image_dict(self):
        d = {
            "image_id": self.image_id,
            "url": self.url
        }
        return d
예제 #25
0
class HouseType(db.Model):
    """房屋类型"""
    __tablename__ = "t_house_type"
    __table_args__ = {"useexisting": True}

    type_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(10))

    def to_dict(self):
        """将对象转换为字典"""
        d = {
            "aid": self.type_id,
            "aname": self.name
        }
        return d
예제 #26
0
class HouseTag(db.Model):
    __tablename__ = "t_house_tag"
    __table_args__ = {"useexisting": True}

    tag_id = db.Column(db.Integer, primary_key=True)
    house_id = db.Column(db.Integer)
    content = db.Column(db.String)

    def to_tag_dict(self):
        if self:
            d = {
                "tag_id": self.tag_id,
                "content": self.content
            }
            return d
        return None
예제 #27
0
class Area(db.Model):
    __tablename__ = "t_area"
    __table_args__ = {"useexisting": True}

    area_id = db.Column(db.Integer, primary_key=True)
    name = db.Column("name", db.String)

    def to_dict(self):
        """将对象转换为字典"""
        d = {
            "area_id": self.area_id,
            "name": self.name
        }
        return d

    def __repr__(self):
        return '<Area %r>' % self.name
예제 #28
0
class User(BaseModel, db.Model):
    """用户"""

    __tablename__ = "ih_user_profile"

    id = db.Column(db.Integer, primary_key=True)  # 用户编号
    name = db.Column(db.String(32), unique=True, nullable=False)  # 用户暱称
    password_hash = db.Column(db.String(128), nullable=False)  # 加密的密码
    mobile = db.Column(db.String(11), unique=True, nullable=False)  # 手机号
    real_name = db.Column(db.String(32))  # 真实姓名
    id_card = db.Column(db.String(20))  # 身份证号
    avatar_url = db.Column(db.String(128))  # 用户头像路径

    # 在一的一方, 添加relationship, 同时添加反向引用
    houses = db.relationship("House", backref="user")  # 用户发布的房屋
    orders = db.relationship("Order", backref="user")  # 用户下的订单

    # 在User下方增加以下函数
    # 通过property装饰器, 将password函数提升为属性
    @property
    def password(self):
        # 在属性的getter方法中, 禁止访问密码数据
        raise AttributeError('禁止访问用户密码')

    @password.setter
    def password(self, value):
        # 在属性的setter方法中执行加密处理
        # 直接传入value即可, 默认sha256, 并会生成随机的8位盐值
        self.password_hash = generate_password_hash(value)

    # 在User下方增加以下函数
    def check_password(self, value):
        """检查用户密码, value 是用户填写密码"""
        return check_password_hash(self.password_hash, value)

    def to_dict(self):
        """将对象转换为字典数据"""
        user_dict = {
            "user_id":
            self.id,
            "name":
            self.name,
            "mobile":
            self.mobile,
            "avatar":
            constants.QINIU_URL_DOMAIN +
            self.avatar_url if self.avatar_url else '',
            "create_time":
            self.create_time.strftime("%Y-%m-%d %H:%M:%S")
        }
        return user_dict

    def auth_dict(self):
        '''将实名信息转换为字典数据'''
        auth_dict = {
            "user_id": self.id,
            "real_name": self.real_name,
            "id_card": self.id_card
        }
        return auth_dict
예제 #29
0
class User(BaseModel, db.Model):
    """用户"""

    __tablename__ = "ih_user_profile"

    id = db.Column(db.Integer, primary_key=True)  # 用户编号
    name = db.Column(db.String(32), unique=True, nullable=False)  # 用户暱称
    password_hash = db.Column(db.String(128), nullable=False)  # 加密的密码
    mobile = db.Column(db.String(11), unique=True, nullable=False)  # 手机号
    real_name = db.Column(db.String(32))  # 真实姓名
    id_card = db.Column(db.String(20))  # 身份证号
    avatar_url = db.Column(db.String(128))  # 用户头像路径
    houses = db.relationship("House", backref="user")  # 用户发布的房屋
    orders = db.relationship("Order", backref="user")  # 用户下的订单

    @property
    def password(self):
        raise AttributeError("不允许此操作")

    @password.setter
    def password(self, value):
        self.password_hash = generate_password_hash(value)

    def chek_password(self, value):
        return check_password_hash(self.password_hash, value)

    def to_dict(self):
        return {
            "name": self.name,
            "mobile": self.mobile,
            "real_name": self.real_name,
            "id_card": self.id_card
        }
예제 #30
0
파일: models.py 프로젝트: penn525/ihome
class User(BaseModel, db.Model):
    """用户"""

    __tablename__ = "ih_user_profile"

    id = db.Column(db.Integer, primary_key=True)  # 用户编号
    name = db.Column(db.String(32), unique=True, nullable=False)  # 用户暱称
    password_hash = db.Column(db.String(128), nullable=False)  # 加密的密码
    mobile = db.Column(db.String(11), unique=True, nullable=False)  # 手机号
    real_name = db.Column(db.String(32))  # 真实姓名
    id_card = db.Column(db.String(20))  # 身份证号
    avatar_url = db.Column(db.String(128))  # 用户头像路径
    houses = db.relationship("House", backref="user")  # 用户发布的房屋
    orders = db.relationship("Order", backref="user")  # 用户下的订单

    @property
    def password(self):
        # return self.password_hash
        raise AttributeError('改属性只能设置,不能读取')

    @password.setter
    def password(self, origin_password):
        self.password_hash = generate_password_hash(origin_password)

    def __repr__(self):
        return f'<User: {self.name}>'