Hi all,

I'm pretty new to web2py and web app development and I've spend some time
trying to figure out the best way to do this.

I have two tables, house-types and regions. A house-type can exist in many
regions, and a region can have many house types:

db.define_table(
    'region',
    Field('name', 'string', length=512, required=True),
    format = '%(name)s')

db.define_table(
    'house-type',
    Field('title', 'string', length=512), #title of the newbuild property
listing
    Field('vendor',db.vendor, required=True),
    Field('bedrooms', 'integer'),
    Field('price', 'double',required=True),
    Field('description', 'text',length=65536, required=True),
    Field('live', 'boolean', default=False)
    )

If I understand correctly, in order to create the many-to-many relationship
I should create a junction table like the following:

db.define_table(
   'houses_and_regions',
   Field('house', db.house-type),
   Field('region', db.region))

And then I should use SQLFORM to construct a form which updates both
house-type and houses_and_region tables when I create or modify a new house.

What I'm struggling with is how to create a form which allows me to select
multiple regions for a house. I wondered if anyone could give me any
examples?

Thanks in advance!

Chris

Reply via email to