Last active
July 18, 2016 12:48
-
-
Save otech-nl/f1f7251e5d0aefb5336cfe6896bcf5b8 to your computer and use it in GitHub Desktop.
Inspect a SQLAlchemy Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://docs.sqlalchemy.org/en/latest/faq/ormconfiguration.html#how-do-i-get-a-list-of-all-columns-relationships-mapped-attributes-etc-given-a-mapped-class | |
from sqlalchemy import inspect | |
from models import * | |
mapper = inspect(Task) | |
for f in 'attrs column_attrs relationships all_orm_descriptors columns'.split(): | |
print '%s:'% f | |
for x in getattr(mapper, f): | |
print ' %s' % x | |
for f in 'mapped_table local_table'.split(): | |
print '%s: %s' % (f, getattr(mapper, f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment