title: Automatically update model relationship after saving to the DB
body: <p>Let's say I have the following two Django models <code>A</code> and <code>B</code>:</p>
  
  <pre><code>class A(models.Model):
      pass
  
  class B(models.Model):
      a = models.ForeignKey('A', on_delete=models.CASCADE)
  </code></pre>
  
  <p>I would like to instantiate both of them and then save them to the DB in the following way:</p>
  
  <pre><code># Code sample 1
  a = A()
  b = B()
  b.a = a
  # Do something with b.a, e.g. b.a.some_method()
  a.save()
  b.save()
  </code></pre>
  
  <p>Although <code>a</code> has been saved to the DB before <code>b</code> and therefore already has an ID, <code>b.save()</code> will fail with an <code>IntegrityError</code>:</p>
  
  <pre><code>IntegrityError: null value in column "a_id" violates not-null constraint
  DETAIL:  Failing row contains (1, null).
  </code></pre>
  
  <p>As a "workaround", it is possible to re-assign <code>a</code> to <code>b</code> before calling <code>b.save()</code>:</p>
  
  <pre><code># Code sample 2
  a = A()
  b = B()
  b.a = a
  # Do something with b.a, e.g. b.a.some_method()
  a.save()
  b.a = a
  b.save()
  </code></pre>
  
  <p>This works but it seems redundant having to assign <code>a</code> to <code>b</code> twice. It feels like <code>b</code> should know about <code>a</code> having changed or having been saved to the DB. Is there a way to make code sample 1 work?</p>