ORM 事务

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))

 

posted @ 2018-11-02 23:04  就俗人一个  阅读(171)  评论(0编辑  收藏  举报