[sqlalchemy] Re: Model to Dictionary

2007-07-25 Thread Jonathan Ellis
why not just pass model_instance.__dict__ ? On 7/23/07, HiTekElvis [EMAIL PROTECTED] wrote: Anybody know a way to change a model into a dictionary? For those to whom it means anything, I'm hoping to pass that dictionary into a formencode.Schema.from_python method. Any ideas? -Josh

[sqlalchemy] Re: Model to Dictionary

2007-07-24 Thread King Simon-NFHD78
What do you mean by a model? If you are talking about an instance of a mapped class, you could try something like this (untested): def model_to_dict(instance): model_dict = {} for propname in instance.mapper.props: model_dict[propname] = getattr(instance, propname) return