Thanks, that did the trick.

On Wed, Jun 27, 2012 at 5:21 AM, Niphlod <[email protected]> wrote:
> hey, requires is expecting :
> - a validator
> - a list of validators
>
> If you need to have a "last_modified" column, i.e. gets a value only when
> row is updated, than:
>
>
> db.define_table(
>     'sometb',
>     Field('name', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
> 'sometb.name')]),
>     Field('last_modified', 'datetime', update=request.now),
>     format='%(name)s'
> )
>
> if you want also the column to have a value when the row is inserted, than:
>
>
> db.define_table(
>     'sometb',
>     Field('name', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
> 'sometb.name')]),
>     Field('created_or_last_modified', 'datetime', update=request.now,
> default=request.now),
>     format='%(name)s'
> )
>
> to exclude that "by default" in forms, you can set its readable and writable
> attributes to False, i.e.
>
>     Field('created_or_last_modified', 'datetime', update=request.now,
> default=request.now, writable=False, readable=False),
>
>
> On Tuesday, June 26, 2012 9:03:40 PM UTC+2, Alec Taylor wrote:
>>
>> I'm confused at how to implement automatic timestamps to tables.
>>
>> So I want to know when each record was created (might have a separate
>> field for "last modified").
>>
>> The form should either have an uneditable field with the current
>> timestamp xor—preferably—it shouldn't be present in the form.
>>
>> Here's a test-case:
>>
>> # Models
>>
>> from datetime import datetime
>>
>> db.define_table(
>>     'sometb',
>>     Field('name', requires=[IS_NOT_EMPTY(), IS_NOT_IN_DB(db,
>> 'sometb.name')]),
>>     Field('date_created', 'datetime', requires=datetime.now,
>> default=datetime.now),
>>     format='%(name)s'
>> )
>>
>> # Controllers
>>
>> def sometb():
>>     return dict(tbform=crud.create(db.group_of_events))
>>
>> # Views
>>
>> {{if 'tbform' in globals():}}
>> {{=tbform}}
>> {{else:}}
>> <h5>Form not found :[</h5>
>> {{pass}}
>>
>> # {{pass}}!
>>
>> Thanks for your time,
>>
>> Alec Taylor
>
> --
>
>
>

-- 



Reply via email to