This is almost but not quite what I want. In your example, if the dictionary includes keys that do not map to object fields, it will throw. I want to try and 'cherry-pick' fields of the object from the dictionary.
With the introspect you gave me I can do that. Thanks, Dan On Monday, January 28, 2019 at 1:57:44 PM UTC+2, dan.b...@huawei.com wrote: > > > Lets say I have a class > > class Dog(AlchemyBase): > __tablename__ = 'dogs' > name = Column(String, primary_key=True) > color = Column(String) > flees = relationship("Flee", backref="dogs") > > > > How can I get the list of fields ['name', 'color', 'flees'] from the class? > > I'd like to write a generic load(Dog, dict) method, that will create a > Dog() with the field values that exist in dict. > > e.g. > d = {'name: 'snoopy', 'junk': 1} > dog = load(Dog, d) > is equivalent to dog = Dog(name = 'snoopy') > > d1 = {'alias' : 'kitti'} > but load(Cat, d1) > is equivalent to cat = Cat(alias = 'kitti) > > Load will pick field names that exist in the passed Object, and have a > value in dict > > Thanks, > Dan > > -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.