title: Django get access to foreign key of current object in views.py
body: <p>I have three models:</p>
  <pre><code>Class Collection(models.Model):
      var_1 = .....
      var_2 = ....
  
  Class Titles(models.Model):
      var_a = models.ForeignKey(Collection,
      related_name=&quot;has_titles&quot;, on_delete=models.CASCADE)
      var_b = ...
  
  Class OtherObject(models.Model):
      var_x = models.ForeignKey(Collection,
      related_name=&quot;has_other_object&quot;, on_delete=models.CASCADE)
      var_y = ...
  </code></pre>
  <p>In views.py I use CBV DetailView with a form in it (using then formMixin or MultipleFormsMixin, but this is not the point).</p>
  <p>So basically each Title is linked to a Collection by a ForeignKey and each OtherObject is linked to a Collection by a ForeignKey as well.</p>
  <p>So, when the user is in a detail page of Title model, he has the posibility to fill in a form to add a OtherObject, that will then be displayed on the Collection detailView that is linked to the Title.</p>
  <p>In other words, what I want is var_x = var_a of current Title :</p>
  <pre><code>if form.is_valid():
      new_other_object = form.save(commit=False)
      new_other_object.var_x = HERE I WANT TO GET var_a OF CURRENT OBJECT
      new_other_object.save()
  </code></pre>
  <p>So, as Title has a ForeignKey containing the ID to Collection it belongs to, I tried to use things such as self.get_object(). I read things such as using self.get_object().var_a could work but with all the different solutions I tried I got errors, mainly the error mentionning that object must be an instance of Collection.</p>
  <p>How would you achieve this?</p>
  <p>Thanks.</p>