orm 事务:
import datetime from appxx import models try: from django.db import transaction with transaction.atomic(): new_publisher = models.Publisher.objects.create(name="苹果出版社") models.Book.objects.create(title="追风筝的人", publish_date=datetime.date.today(), publisher_id=10) except Exception as e: print(str(e))