Skip to content

Instantly share code, notes, and snippets.

@agmond
Created January 2, 2018 16:19
Show Gist options
  • Save agmond/d7833dc3e3c01ea2d21fd0be4fa02e1f to your computer and use it in GitHub Desktop.
Save agmond/d7833dc3e3c01ea2d21fd0be4fa02e1f to your computer and use it in GitHub Desktop.
Interactively dry-run Django code that changes data in the DB, with ability to commit at the end
from django.db import transaction
t = transaction.atomic()
t.__enter__()
# Do your stuff here...
pass
# If you want to *rollback* you changes:
t.__exit__('temp', 'temp', 'temp')
# If you want to *commit* your changes:
t.__exit__(None, None, None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment