Skip to content

Instantly share code, notes, and snippets.

@m1yag1
Forked from kennyledet/sqlalchemy_dupe_row
Last active August 29, 2015 14:25
Show Gist options
  • Save m1yag1/ce87939f940034e7651b to your computer and use it in GitHub Desktop.
Save m1yag1/ce87939f940034e7651b to your computer and use it in GitHub Desktop.
SQLAlchemy Duplicate Row
def copy_row(model, row, ignored_columns=[]):
copy = model()
for col in row.__table__.columns:
if col.name not in ignored_columns:
try:
copy.__setattr__(col.name, getattr(row, col.name))
except Exception as e:
print e
continue
return copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment