django事务模式

from django.db import transaction
from django.db import transaction
            with transaction.atomic():
                obj = models.Article.objects.create(**form.cleaned_data)
                models.ArticleDetail.objects.create(content=content, article=obj)
                tag_list = []
                for tag_id in tags:
                    tag_id = int(tag_id)
                    tag_list.append(models.Article2Tag(article_id=obj.nid, tag_id=tag_id))
                models.Article2Tag.objects.bulk_create(tag_list)

  

posted @ 2018-06-22 00:33  梦中琴歌  阅读(215)  评论(0编辑  收藏  举报