Hi,
Not really as new to this and working my way through it slowly, but best I
keep on searching
cheers
Anthony
On Tuesday, 15 December 2015 05:19:30 UTC+11, villas wrote:
>
> By 'prototype' I believe he means the record which you wish to use as a
> 'template'.
>
> 1. Find your 'template' record which will be used for setting the default
> values of the fields in the new record.
> 2. Set the field.default accordingly.
> 3. Do not pass a record to SQLFORM. If you do, it will update that
> record. It is presumed that you will wish to create a new record.
>
> Hope that helps to clarify ValK's response.
> All the best.
>
>
> On Sunday, 13 December 2015 17:53:36 UTC, Anthony Smith wrote:
>>
>> Hi Val,
>>
>> Thanks for your reply, but unable to find any about get prototype record
>> in the book.
>>
>> Do you have an examples
>>
>> Thanks
>>
>> Anthony
>>
>> On Saturday, 12 December 2015 06:03:26 UTC+11, Val K wrote:
>>>
>>> 1. get prototype record
>>> 2. overwrite field.default with corresponding prototype value
>>> 3. don't pass record to SQLFORM
>>>
>>> On Monday, December 7, 2015 at 7:15:46 AM UTC+3, Anthony Smith wrote:
>>>>
>>>> Hi All,
>>>>
>>>> I have a products table:
>>>> db.define_table('product',
>>>> Field('product_name'),
>>>> Field('active_ingredient'),
>>>> Field('batch_no'),
>>>> Field('expiry_date','date'),
>>>> Field('product_type',
>>>> requires=IS_IN_SET(PRODUCTTYPES),default= PRODUCTTYPES[0]),
>>>> Field('withholding_period','integer'),
>>>> Field('ESI_withholding','integer'),
>>>> Field('qty','integer'),
>>>> Field('date_purchased','date', default = request.now),
>>>> Field('purchased_from',
>>>> requires=IS_IN_DB(db,'company.company_name','%(company_name)s')),
>>>> (auth.signature),
>>>> format='%(product_name)s %(batch_no)s')
>>>>
>>>> I can edit the product with the following controller:
>>>> def edit_product():
>>>> product_id = request.args(0,cast=int)
>>>> product = db.product(product_id) or error()
>>>> if not product.created_by==me:
>>>> product.created_by.writable = True
>>>> else:
>>>> product.created_by.writable = False
>>>> form = SQLFORM(db.product,product,
>>>> showid=False,
>>>>
>>>> deletable=(product.created_by==me)).process(onsuccess=auth.archive)
>>>> if form.accepted:
>>>> session.flash="Edit Successful"
>>>> redirect(URL('products'))
>>>> return locals()
>>>>
>>>> At times I need to add new products but only some of the fields change
>>>> E.G. batch_no, expiry_date, and supplier.
>>>> In short if need to add similar item that I already have in the
>>>> products table
>>>>
>>>>
>>>> thanks
>>>>
>>>> Anthony
>>>>
>>>>
>>>>
--
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.