[web2py] Re: Is it possible to update or insert object to database in one command?

2011-03-25 Thread Massimo Di Pierro
object_o = db.t_table(f_name='same name') or db.t_table[db.t_table.insert(f_name="some name")] On Mar 25, 7:21 am, Sergey Ozhigin wrote: > Thanks for answers, i will try that. > > Now, what about task "get object if exists, or create and get object > if it doesn't exist"? > > I use folowing co

[web2py] Re: Is it possible to update or insert object to database in one command?

2011-03-25 Thread Sergey Ozhigin
Thanks for answers, i will try that. Now, what about task "get object if exists, or create and get object if it doesn't exist"? I use folowing construction: object_o="" try: q= db.t_table.f_name == "some name" object_o=next(iter(db(q).select())) except: object_o=db.t_tabl

[web2py] Re: Is it possible to update or insert object to database in one command?

2011-03-25 Thread carlo
This is the kind of thing I would love to find in a handy Web2py Cookbook! carlo On 24 Mar, 14:27, Massimo Di Pierro wrote: > You can do it without if as well: > > db(query).update(...) or db.mytable.insert(...) > > On Mar 24, 8:26 am, Massimo Di Pierro > wrote: > > > To know if it exist or not

[web2py] Re: Is it possible to update or insert object to database in one command?

2011-03-24 Thread Massimo Di Pierro
You can do it without if as well: db(query).update(...) or db.mytable.insert(...) On Mar 24, 8:26 am, Massimo Di Pierro wrote: > To know if it exist or not you must have condition in the form of a > query. You can do > > if not db(query).update(...): db.mytable.insert(...) > > where ... is the

[web2py] Re: Is it possible to update or insert object to database in one command?

2011-03-24 Thread Massimo Di Pierro
To know if it exist or not you must have condition in the form of a query. You can do if not db(query).update(...): db.mytable.insert(...) where ... is the field='value' list. On Mar 24, 4:46 am, Sergey Ozhigin wrote: > Hello, > > Is it possible in web2py to update or insert object (if doesn't