This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
sqlalchemy_notes [2019/07/24 01:42] root [ORM Working with Existing Tables] |
sqlalchemy_notes [2019/07/24 01:45] (current) root [ORM Working with Existing Tables] |
||
---|---|---|---|
Line 154: | Line 154: | ||
mapper(Designs, designs) | mapper(Designs, designs) | ||
</code> | </code> | ||
+ | |||
+ | == Mapping Json to Table Class == | ||
+ | if the key's match the table/object fiends then you can | ||
+ | |||
+ | <code python> | ||
+ | user = User(**obj) | ||
+ | </code> | ||
+ | |||
+ | if you have in your json fields that don't belong to that model you can filter them out with dict comprehension | ||
+ | |||
+ | <code python> | ||
+ | user = User(**{k:v for k, v in obj.items() if k in {'id', 'name'}}) | ||
+ | </code> | ||
+ |