Last active
December 27, 2015 11:59
-
-
Save craiglabenz/7323056 to your computer and use it in GitHub Desktop.
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
@classmethod | |
def my_func(cls, *args): | |
''' | |
A model function -- not a full Django View. | |
''' | |
with transaction.commit_manually(using='custom_connection'): | |
obj = OtherModel.objects.get(...) | |
try: | |
# do stuff | |
obj.save() | |
except: | |
# do other stuff | |
obj.save() | |
print 'pre-commit' | |
transaction.commit() | |
print 'post-commit' | |
RESULTS IN: | |
>>> MyClass.my_func() | |
>>> 'pre-commit' | |
>>> TransactionManagementError: This code isnt under transaction management. | |
** Note that the `obj.save()` line hits and is reflected by my database. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment