30👍
✅
Since Django 1.7, Connection.in_atomic_block
will tell you if a connection is inside a transaction or not. It doesn’t seem like this is documented, but it Works On My Machine:
from django.db import transaction
cxn = transaction.get_connection()
if cxn.in_atomic_block:
print "We're inside a transaction!"
4👍
Since Django 1.6 you can tell if you’re in autocommit mode via transaction.get_autocommit API.
from django.db import transaction
if transaction.get_autocommit():
pass # We are in autocommit
- Django – How ModelChoiceField queryset's works?
- How to order a Django Rest Framework ManyToMany related field?
- Django signal m2m_changed not triggered
2👍
You can check if you are in a transaction by checking is_managed
if transaction.is_managed():
print "tutsi frutsi!"
- Django: efficient template/string separation and override
- Django : Static content not found
- Single sign on to Django site via remote Active Directory
- Django-filter with DRF – How to do 'and' when applying multiple values with the same lookup?
- Django error cannot import name 'RemovedInDjango30Warning'
Source:stackexchange.com