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)

浙公网安备 33010602011771号