-
-
Save m1yag1/ce87939f940034e7651b to your computer and use it in GitHub Desktop.
SQLAlchemy Duplicate Row
This file contains 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
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