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.

Reply via email to