There are several ways:
0:
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Advanced-features
1: def predefined_field(): return Field(...) # now, in any table
definition you can just: db.define_tabel(..., Field(...),
predefined_field(), ...)
2: Also, there is undocumented function : db.any_table.any_field.clone() -
returns copy of the field (decoupled from the table) + you can pass args
to overwrite any fields properties: db.any_table.any_field.clone(name =
'another_name')
On Saturday, December 1, 2018 at 10:41:54 PM UTC+3, mostwanted wrote:
>
>
> I am trying to achieve something here, i have two tables and i want the
> values of one table to be default values of another table so that i don't
> have to re enter the same information over & over again: In the code below
> observe where highlited in green, is there a way for me to do something
> like below.
>
> *CODE*:
> db.define_table('quotationClient',
> Field('Client_Surname'),
> Field('Client_Name'),
> Field('Company'),
> Field('Contact_Details'),
> Field('Book_In', 'date'),
> Field('Book_Out', 'date'),
> Field('Days', compute=lambda r: (r['Book_Out']-r['Book_In'
> ]).days),
> Field('Booked_By', 'reference auth_user', default=auth.
> user_id, writable=False, label=SPAN('Booked In By', _style="font-weight:
> bold;")),
> Field('Booking_Date', 'datetime', default=request.now,
> writable=False, label=SPAN('Booking Date', _style="font-weight: bold;")),
> format="%(Client_Surname)s %(Client_Name)s"
> )
>
> db.define_table('quotation',
> Field('customer', 'reference quotationClient', writable=
> False),
> Field('Quotation_For'),
> *#HOW CAN I DO THE BELOW IN SUCH A WAY THAT WORKS*
>
> * Field('Book_In', 'date', default='db.quotationClient.Book_In',
> writable=False, readable=False), Field('Book_Out', 'date',
> default='db.quotationClient.Book_Out', writable=False, readable=False),*
> Field('No_of_Pax', 'integer'),
> Field('Days', compute=lambda r: (r['Book_Out']-r['Book_In'
> ]).days),
> #Field('No_of_Days', 'integer'),
> Field('Unit_Price', 'integer'),
> #Field('vat', compute=lambda r:
> int(r['Days'])*r['Unit_Price']*r['No_of_Pax']*0.1),
> Field('Amount', compute=lambda r: int(r['Days'])*r[
> 'Unit_Price']* r['No_of_Pax']),
> Field('Quoted_By','reference auth_user', default=auth.
> user_id, writable=False),
> Field('Quoted_On','datetime',default=request.now,writable=
> False))
>
> Mostwanted
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.