def __init__( me, **ka): for k,v in ka.iteritems(): setattr( me,k,v) def update( me, ka): for k,v in ka.iteritems(): setattr( me,k,v)
generic repr/str is more tricky... one way is like: for p in object_mapper(self).iterate_properties: print getattr( self, p.key) or was it something similar... be careful with recursive a-b-a or a-a relations... if u want a sort-of fool proof generic str, see here: https://dbcook.svn.sourceforge.net/svnroot/dbcook/static_type/util/str.py ciao svilen On Monday 12 January 2009 18:24, Christoph Haas wrote: > Dear list, > > I used to use a certain ORM base class with SQLA 0.4 for a while. It > defined __init__, __repr__ and update so that I could preset mapped > objects with values like > > leo = User(name='leo', age=23) > > or just > > print leo > > and especially > > leo.update(dictionary_from_web_form) > > I couldn't find it on the wiki anymore. And what I use here doesn't work > properly on 0.5 (it relies heavily on the 'c' attribute and just removing > it doesn't solve things because it tries "if a_certain_attribute in > this_object.c"). > > If anyone has "ported" that few lines of code to 0.5 please let me know. > > I thought that the declarative_base helps here but it's just helping with > the declaration. > > Cheers > Christoph --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---