title: Django UpdateView with related model
body: <p>I have the following situation and I don't know how to do an update:</p>
  
  <pre><code>#models.py
  class Task(models.Model):
      creation_date = models.DateField(
          default=None,
      )
      name = models.CharField(
          max_length=255,
      )
      description = models.TextField(
          max_length=500,
          blank=True,
          null=True, 
      )
  
  class TaskDetails(models.Model):
      PEND = 1
      COMP = 2
      TASK_STATUS = (
          (PEND, 'pending'),
          (COMP, 'completed'),
      )
      task = models.OneToOneField(
          Task,
          primary_key=True, 
          on_delete=models.CASCADE
      )
      solution = models.CharField(
          max_length=255,
      )
      due_date = models.DateField(
          null=True,
          default=None,
          blank=True,
      )    
      status = models.PositiveSmallIntegerField(
          default=1,
          choices=TASK_STATUS,
      )
  </code></pre>
  
  <p>And now my view</p>
  
  <pre><code>#views.py
  class TaskUpdate(UpdateView):
      model = Task
      second_model = TaskDetails
      form_class = TaskForm
      second_form_class = TaskDetailsForm
      pk_url_kwarg = 'task_id'
  
      def get_context_data(self, **kwargs):
          context = super(TaskUpdate, self).get_context_data(**kwargs)
          if self.request.method == 'POST':
              details_form = self.second_form_class(self.request.POST, prefix='details')
          else:
              details_object = self.second_model.objects.get(pk=self.kwargs.get(self.pk_url_kwarg))
              details_form = self.second_form_class(instance=details_object, prefix='details')
  
          context['details_form'] = details_form
          return context
  
      def post(self, request, *args, **kwargs):
          self.object = self.get_object()
          form = self.form_class(request.POST)
          details_form = self.second_form_class(request.POST, prefix='details')
          if form.is_valid() and details_form.is_valid():
              return self.form_valid(form, details_form)
          else:
              return self.form_invalid(form, details_form)
  
      def form_valid(self, form, details_form):
          form.instance.creation_date = datetime.now().date()
          self.object = form.save()
          details_form.instance.task = self.object
          details_form.save()
          return HttpResponseRedirect(self.success_url)
  
      def form_invalid(self, form, details_form):
          return self.render_to_response(self.get_context_data(form=form, details_form=details_form))
  </code></pre>
  
  <p>I also have the ModelForms: <em>TaskForm</em> and <em>TaskDetailsForm</em>. Not relevant here.
  The 2 forms are displayed and submitted at once.
  But instead of updating the existing record in Task and TaskDetails tables, it creates a new one in both tables</p>
  
  <p>I think my problem is in <strong>form_valid</strong>. What should I put there?
  Thanks a lot</p>