我不知道如何在 FormAlchemy 中制作级联选择框。像地址选择表一样,我们有四个类:
class Country(Base, DBBase):
__tablename__ = 'countries'
id = Column(Integer, primary_key = True)
name = Column(String)
def __init__(self, name):
self.name = name
class Province(Base, DBBase):
__tablename__ = 'provinces'
id = Column(Integer, primary_key = True)
country_id = Column(Integer, ForeignKey('countries.id'), nullable = True)
country = relationship('Country', backref = 'provinces')
name = Column(String)
def __init__(self, country, name):
self.country = country
self.name = name
class City(Base, DBBase):
__tablename__ = 'cities'
id = Column(Integer, primary_key = True)
province_id = Column(Integer, ForeignKey('provinces.id'), nullable = True)
province = relationship('Province', backref = 'cities')
name = Column(String)
def __init__(self, province, name):
self.province = province
self.name = name
class District(Base, DBBase):
__tablename__ = 'districts'
id = Column(Integer, primary_key = True)
city_id = Column(Integer, ForeignKey('cities.id'), nullable = True)
city = relationship('City', backref = 'districts')
name = Column(String)
def __init__(self, city, name):
self.city = city
self.name = name
当用户从第一级选择框(这里是国家字段)中选择一个选项时,第二级选择框应该列出属于相应第一级选择框的所有内容(如果您在“国家”字段中选择美国,“省/州”字段应显示所有州属于美国)。三级和四级盒子就是这样。所有数据都像上面的四个类一样排序。问题是如何在 FormAlchemy 中制作这样的表格?