I am trying to use the first method but i am failing to get the desired results, how do i check the availability of the selected and wanted room?? This is my controller code but i figured it not gonna give me results even when i started writing it:
*CONTROLLER:* *def index(): form=SQLFORM(db.rooms) if form.accepts(request.vars, session): space=db(db.rooms).select(db.rooms.ALL) for sp in space: if sp.vailable==True: response.flash = T("CLIENT BOOKED") elif sp.vailable==False: db.rollback() response.flash = T("FAILED") return locals();* *MODEL* *db.define_table('client', Field('Name'), Field('Surname'), Field('age'), format='%(Name)s')db.define_table('room_numbers', Field('room'), format='%(room)s')db.define_table('rooms', #Field('room_number'), Field('room', 'reference room_numbers'), Field('available', 'boolean'), Field('occupant', 'reference client'))* On Saturday, September 22, 2018 at 1:06:24 AM UTC+2, Dave S wrote: > > > > On Friday, September 21, 2018 at 2:35:33 PM UTC-7, Dave S wrote: >> >> >> >> On Friday, September 21, 2018 at 9:54:00 AM UTC-7, mostwanted wrote: >>> >>> How do i get a value stored in the database to be selected only once by >>> users? I am creating a hotel system and in this system i have to make sure >>> that a room can not be double booked, it can only be selected once for one >>> client. >>> >>> Regards >>> >>> Mostwanted >>> >> >> >> There are a couple of ways I can think of. >> >> The most obvious way would to be include a boolean field in your room >> record, call it "available". >> >> db.define_table('room', >> Field('available', 'string'), >> Field('roomnum', 'integer'), >> Field('numsleeps', 'integer'), >> Field('occupant', refence 'account')) >> >> >> > I forgot a field for non-smoking, so assume *all* rooms are non-smoking > at this point. > > >> Your controller function that assigns the room to an occupant would >> update both fields, but only if 'available' was True when fetched. This >> relies on the web2py default that an http request is performed as a single >> transaction. >> >> > Note: it's a matter of choice as whether you call the field 'available' > or 'in_use'; go with what makes sense in terms of business logic and/or the > surrounding code. But spell 'reference' correctly, of course. > > Another technique would be to have a separate table tracking available > rooms, and delete the entry when the room is assigned. > > db.define_table('available', > Field('room', reference 'room')); > > > You can also track rooms-in-use if you prefer, but I think that's more > complicated for finding an available room. You can use both lists, and > swap from one to another at appropriate times, and you can add additional > states (such as for being remodeled or deep-cleaned). > > Someone of faster wit than mine may offer up yet another way of achieving > your goal. > > /dps > > > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.