Use the new django transaction API

fixes #1027
Merge pull request #1361 from ostcar/transaction

Used the new django transaction API.