Saving objects and their related objects at the same time in Django
<p>In Django, is there a way to create a object, create its related objects, then save them all at once?</p>

<p>For example, in the code below:</p>

<pre><code>from django.db import models


class Post(models.Model):
    title = models.CharField(max_length=255)
    body = models.CharField(max_length=255)


class Tag(models.Model):
    post = models.ForeignKey(Post)
    title = models.CharField(max_length=255)

post = Post(title='My Title', body='My Body')
post.tag_set = [Tag(post=post, title='test tag'), Tag(post=post, title='second test tag')]
post.save()
</code></pre>

<p>I create a Post object. I then also want to create and associate my Tag objects. I want to avoid saving the Post then saving the Tags because if a <code>post.save()</code> succeeds, then a <code>tag.save()</code> fails, I'm left with a Post with no Tags.</p>

<p>Is there a way in Django to save these all at once or at least enforce better data integrity?</p>