Hi All,

I must be missing something, I've read the book's chapter on SQLFORM
and the bit about "Links to referencing records" but I still can't get
my head round how to make a compound form, i.e. one with fields from
multiple tables. Here's are my tables...

db.define_table('CONTACTS',
    SQLField('contact_name','string',length=255, required=True),
    SQLField('date_added','datetime', required=True)
    )
db.CONTACTS.contact_name.requires=[ IS_NOT_EMPTY(), IS_LENGTH
(255,error_message=T('name too long, max(255)')) ]
db.CONTACTS.date_added.requires=[ IS_DATETIME() ]


db.define_table('EMAIL_ADDRESSES',
    SQLField('contact_id',db.CONTACTS, required=True),
    SQLField('email_address','string',length=255, required=True),
    SQLField('the_default','boolean', default=False, required=True)
    )
db.EMAIL_ADDRESSES.contact_id.requires=[ IS_IN_DB(db,
db.CONTACTS.id) ]
db.EMAIL_ADDRESSES.email_address.requires=IS_EMAIL()


This is my view...

def index():
    cf1 = SQLFORM( db.CONTACTS )
    if cf1.accepts(request.vars,session):
        response.flash="Contact added."
    return dict( form=cf1 )

The natural thing seemed to be to try:
     cf1 = SQLFORM( db.CONTACTS, db.EMAIL_ADDRESSES )
but that barfed, so next I tried...
    cf1 = SQLFORM( db.CONTACTS, db.EMAIL_ADDRESSES, fields=
["contact_name","email_address"])
which barfs also. I also tried...
    cf1 = SQLFORM( db.CONTACTS.id==db.EMAIL_ADDRESSES.contact_id,
fields="contact_name" )
with the same result.

Am I missing something small or am I going about it entirely the wrong
way?

Thanks,

Roger.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to