[sqlalchemy] Re: setattr and mapped ORM
On Wed, 2009-10-21 at 09:24 -0700, David Gardner wrote: Using setattr() shouldn't be a problem, however the __dict__ attribute also has other things in there like _sa_instance_state that I don't believe you want to copy to the new item. Try this instead: for col in object_mapper(update): setattr(proxy,col.key,getattr(update,col.key)) Hum hum Object Mapper is not Callable So I don't understand what you mean. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: setattr and mapped ORM
On Wed, 2009-10-21 at 09:24 -0700, David Gardner wrote: Using setattr() shouldn't be a problem, however the __dict__ attribute also has other things in there like _sa_instance_state that I don't believe you want to copy to the new item. Try this instead: for col in object_mapper(update): setattr(proxy,col.key,getattr(update,col.key)) OK thanks. After doing some introspection: proxy User record: None None update User record: francois tretre for c in user_mapper.c: ... setattr(proxy, c.key, getattr(update, c.key)) ... proxy User record: francois tretre And of course user_mapper = mapper(User, user_table) L.FRANCOIS --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: setattr and mapped ORM
Using setattr() shouldn't be a problem, however the __dict__ attribute also has other things in there like _sa_instance_state that I don't believe you want to copy to the new item. Try this instead: for col in object_mapper(update): setattr(proxy,col.key,getattr(update,col.key)) laurent FRANCOIS wrote: Hello, I'm trying to have a GUI as a CRUD (create-record-update-delete) User is a simple ORM class mapped to a table. class User(object): def __init__(self, fname=None, lname=None): self.lname = lname self.fname = fname def __repr__(self): return 'Patient record:%s %s' %(self.fname, self.lname) user_mapper = mapper(User, user_table) proxy = User() update = User(fname='FOO', lname='BAR') for k,v in update.__dict__.items(): setattr(proxy, k, v) lname BAR _sa_instance_state sqlalchemy.orm.identity.IdentityManagedState object at 0x9affeec fname None * I try to update an object User with an other object User. And it's not working. (fname stay None). Is anybody as some informations and explanations about this behavior? Thanks L.FRANCOIS -- David Gardner Pipeline Tools Programmer Jim Henson Creature Shop dgard...@creatureshop.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---