Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-21 Thread Simon King
Are you flushing the same session that was used to load the record? What session does get_instance use? Simon On Mon, Aug 21, 2017 at 7:47 AM, pravin battula wrote: > I did as below. But didn't work. Am i missing anything else. > > def update_record(session, id): >

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-21 Thread pravin battula
I did as below. But didn't work. Am i missing anything else. def update_record(session, id): record_instance = get_instance(id) if record_instance: updateobj(record_instance, {'time_zone':'GMT','status':'done'}) session.flush() session.commit() def updateobj(obj,

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread Simon King
No, but you can trivially write your own function to do it: def updateobj(obj, data): for key, value in data.items(): setattr(obj, key, value) Simon On Fri, Aug 18, 2017 at 3:14 PM, pravin battula wrote: > The solution which you gave will work but I have a

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread pravin battula
The solution which you gave will work but I have a dict of keys to be updated with that get instance. Is there any specific way of updating something like product_live_time_instance.update(data_dict). On Friday, 18 August 2017 19:21:12 UTC+5:30, Simon King wrote: > > On Fri, Aug 18, 2017 at

Re: [sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread Simon King
On Fri, Aug 18, 2017 at 2:41 PM, pravin battula wrote: > Hi, > > I'm getting an instance of a model using a primary key like below. > product_live_time = session.query(ProductLiveTime).get(product_id) > > Now, i want to update few columns using the same instance

[sqlalchemy] How do I get an object and update multiple fields in sqlalchemy

2017-08-18 Thread pravin battula
Hi, I'm getting an instance of a model using a primary key like below. *product_live_time = session.query(ProductLiveTime).get(product_id)* Now, i want to update few columns using the same instance *product_live_time, *how can i do it without doing filter again like below i.e