Auto-fill Django OneToOneField
<p>This maybe a simple question, but I do not have any idea how to do this.
I have two models in Django.</p>

<pre><code>class ModelA(models.Model):
    some_member = models.Charfield(...)

class ModelB(models.Model):
    model = OneToOneField(ModelA)
    other_member = models.Charfield(...)
</code></pre>

<p><code>ModelA</code> is filled in by a ModelForm and then redirect to the form for <code>ModelB</code>.
How can I Autofill the <code>OneToOneField</code> based on the previous form.
Thank you for helping.</p>

<hr>

<p>I am doing it like this now</p>

<pre><code>class ModelBView(CreateView):
.......
    def form_valid(self, form):
        model_b = form.save(commit=False)
        model_a_form = ModelAForm(self.request.POST)
        model_b.model = model_a_form.save(commit=False)
        model_b.save()
        return super(ModelBView, self).form_valid(form)
</code></pre>

<p>but get the error: "...could not be created because the data didn't validate."</p>

<p>So here the problem is, I simply can get the data from the previous form by request.POST.
How can I get this data.</p>

<p>Maybe you can save the data from ModelForm for ModelA in request.session or request.get and redirect to the next page for ModelB, where you can get the data for model field in ModelB then fill it.</p>

python django forms