very nice, it's work well, thank you so much for your hints, anthony.
just want to share the code that you've guide.

def format_room(record):
    return '%s-%s' % (record.branch.address, record.room_no)

def format_booking(record):
    return '%s-%s %s-%s-%s' % (record.scheduled_start, 
record.guest.first_name,
                               record.guest.last_name, 
record.room.branch.address, 
                               record.room.room_no)

db.define_table('booking',
    Field('scheduled_start', 'datetime'),
    Field('due_date', 'datetime'),
    Field('room', 'reference room', represent=lambda id, r: 
format_room(r.room)),
    Field('guest', 'reference guest'),
    Field('description', 'text'),
    format='%(scheduled_start)s %(guest)s %(room)s')

db.define_table('check_in',
    Field('is_booking', 'boolean'),
    Field('booking', 'reference booking', represent=lambda id, r: 
format_booking(r.booking)),
    Field('room', 'reference room', represent=lambda id, r: 
format_room(r.room)),
    Field('guest', 'reference guest'),
    Field('description', 'text'),
    format='%(guest)s %(room)s')

db.booking.scheduled_start.requires=IS_NOT_EMPTY()
db.booking.due_date.requires=IS_NOT_EMPTY()
db.booking.room.requires=IS_IN_DB(db(db.room.status=='Available'), 
db.room.id, 
                                     label=format_room)
db.booking.guest.requires=IS_IN_DB(db, db.guest.id, 
                                   '%(first_name)s %(last_name)s')
db.booking.description.requires=IS_NOT_EMPTY()

db.check_in.booking.requires=IS_EMPTY_OR(IS_IN_DB(db(db.booking.is_active==True),
 
                                                  db.booking.id, 
label=format_booking))
db.check_in.room.requires=IS_EMPTY_OR(IS_IN_DB(db(db.room.status=='Available'), 
                                               db.room.id, 
label=format_room))
db.check_in.guest.requires=IS_EMPTY_OR(IS_IN_DB(db, db.guest.id, 
                                                '%(first_name)s 
%(last_name)s'))
db.check_in.description.requires=IS_NOT_EMPTY()

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to