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')


# 房屋设施表,建立房屋与设施的多对多关系
# 没有设置id, 联合主键做id
house_facility = db.Table(
    'ihome_python_house_facility',
    db.Column('id', db.Integer, primary_key=True),
    db.Column('house_id', db.Integer, db.ForeignKey('ihome_python_house_info.id')),
    db.Column('facility_id', db.Integer, db.ForeignKey('ihome_python_facility_info.id'))
)

class House(BaseModel):

    __tablename__ = 'ihome_python_house_info'

    id = db.Column(db.Integer, primary_key=True)
    # 在多表中建立外键
    user_id = db.Column(db.Integer, db.ForeignKey('ihome_python_user_profile.id'), nullable=False)
    area_id = db.Column(db.Integer, db.ForeignKey('ihome_python_area_info.id'), nullable=False)

    title = db.Column(db.String(64), nullable=False)  # 标题
    price = db.Column(db.Integer, default=0)  # 单价,单位:分
    address = db.Column(db.String(512), default="")  # 地址
Example #2
0
    houses = db.relationship("House", backref="area")  # 区域的房屋

    def area_dict(self):
        area_dict = {'aid': self.id, 'aname': self.name}
        return area_dict


# 房屋设施表,建立房屋与设施的多对多关系
# 如果是多对多, 直接操作底层的表
house_facility = db.Table(
    "ih_house_facility",
    db.Column("house_id",
              db.Integer,
              db.ForeignKey("ih_house_info.id"),
              primary_key=True),  # 房屋编号
    db.Column("facility_id",
              db.Integer,
              db.ForeignKey("ih_facility_info.id"),
              primary_key=True)  # 设施编号
)


class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号

    title = db.Column(db.String(64), nullable=False)  # 标题
Example #3
0
    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


# 房屋设施表,建立房屋与设施的多对多关系
house_facility = db.Table(
    'ih_house_facility',
    db.Column('hourse_id',
              db.Integer,
              db.ForeignKey('ih_house_info.id'),
              primary_key=True),  # 房屋编号
    db.Column('facility_id',
              db.Integer,
              db.ForeignKey('ih_facility_info.id'),
              primary_key=True)  # 设施编号
)


class House(BaseModel, db.Model):
    """房屋信息"""

    __tablename__ = "ih_house_info"

    id = db.Column(db.Integer, primary_key=True)  # 房屋编号
    user_id = db.Column(db.Integer,
                        db.ForeignKey("ih_user_profile.id"),