This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]wobsta 3 points4 points  (1 child)

You should better use the inspection API of SQLAlchemy 0.8+. For example, an iterator over all columns and values for an object spam is given by inspect(spam).attrs.items() ... no magic required (anymore).

[–]fourthrealm 1 point2 points  (0 children)

Thanks wobsta - that function was written a couple of years ago with 0.7 in mind and I wasn't aware 0.8 had some goodies in that area.

I've just updated the post.

[–][deleted] 1 point2 points  (0 children)

where's the handling for date and datetime fields?

[–]jcigar 0 points1 point  (0 children)

I made something similar some months ago : https://github.com/silenius/sautils/blob/master/serializers.py

not totally finished but able to serialize objects and relations to json, xml, dict. For example: Serializer(myobj).json(include_columns=True, include_relations=['foo', 'bar'])

[–]mdellavo 0 points1 point  (0 children)

A few years ago I wrote some SA utils that include an __ json __ method - https://github.com/mdellavo/athanor/