Does this work:
db.define_table('dogs', ...,
Field('creation_date', 'datetime', default=now),
Field('update_date', 'datetime', default=None, update=now))
Then in your update_or_insert, don't explicitly specify either of those
fields and let the default/update attributes handle it.
Anthony
On Friday, October 31, 2014 5:47:41 PM UTC-4, Luis Ramos wrote:
>
> I'm currently using this method to insert new elements. How can I update
> the 'update_date' field only if there's an update and only insert the
> 'creation_date' one time?
>
> import datetime
>
> now = datetime.datetime.now()
>
> db.define_table('dogs', Field('name'),
> Field('owner'),
> Field('address'),
> Field('creation_date', 'datetime'),
> Field('update_date', 'datetime'))
>
>
> q1 = db.dogs.name == 'Paco'
> q2 = db.dogs.owner == 'Rob'
>
> db.dogs.update_or_insert((q1) & (q2), name='Paco', owner='Rob',
> creation_date=now)
>
--
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.