You may want to add a simple check to this too

def object_creator(obj_class, dict_info):
   obj = obj_class()
   for key, value in dict_info.iteritems():
       if hasattr(obj, key):
          setattr(obj, key, value)
   return obj

this these methods will work nicely and could also be made into a
classmethod

On Thu, Jul 15, 2010 at 2:22 PM, Jonathan Schemoul <
[email protected]> wrote:

> In SQLAlchemy, if you use the declarativebase, it's pretty easy.
>
> Example :
> mydict = {'field1': 'test',
>                 'field2': 'testa'}
>
> myobject = MyClass(**mydict)
>
> Without declarative it's possible also :
>
> def object_creator(obj_class, dict_info):
>    obj = obj_class()
>    for key, value in dict_info.iteritems():
>        setattr(obj, key, value)
>    return obj
>
> myobject = object_creator(MyClass, mydict)
>
> Jon
>
> On Jul 15, 9:41 pm, Gisborne <[email protected]> wrote:
> > I can't seem to locate a command that would create a row in a mapped
> > table given a dict with column names and values.
> >
> > Seems a reasonable thing to want, but if it's in the docs, I'll be
> > blasted if I can find it.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to