Last active
May 27, 2019 18:04
-
-
Save cgthayer/25aa97bb4b74efb75e3467fb7bbdaacb to your computer and use it in GitHub Desktop.
Django: check what would be deleted when I delete an object, using a transaction
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
>>> from django.db import transaction | |
>>> transaction.set_autocommit(autocommit=False) | |
>>> o = Organization_v2.objects.get(name='pdemo') | |
>>> del_info = o.delete() | |
>>> del_info | |
(1404, {'data.Property': 408, [..more stuff..], 'data.Organization_v2': 1}) | |
>>> Property.objects.filter(scope__organization_id=o).count() | |
0 | |
>>> transaction.rollback() | |
>>> o = Organization_v2.objects.get(name='pdemo') | |
>>> Property.objects.filter(scope__organization_id=o).count() | |
408 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment