title: django: How to use inlineformset within the formwizard?
body: <p>I'm displaying two separate sample projects. The first is a Contact related and shows the principle of using the formwizard. The second is an ingredients to recipes related project which shows how to use inlines within a form. I want inlines to be in my formwizard the same way they work in a normal form.</p>
  
  <p>I have a formwizard multistep form working. It is based off the <a href="https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/" rel="nofollow">example here</a>. I've changed it slightly to use modelform.</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>from django.db import models
  
  # Create your models here.
  class Contact(models.Model):
      subject = models.CharField(max_length=50)
      sender = models.EmailField()
  
      def __unicode__(self):
          return self.subject
  
  class Contact2(models.Model):
      message = models.TextField(max_length=500)
  
      def __unicode__(self):
          return self.message
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class ContactForm1(forms.ModelForm):
      class Meta:
          model = Contact
  
  class ContactForm2(forms.ModelForm):
      class Meta:
          model = Contact2
  
  class ContactWizard(FormWizard):
      @property
      def __name__(self):
          return self.__class__.__name__
  
      def done(self, request, form_list):
  #        do_something_with_the_form_data(form_list)
          return HttpResponseRedirect('/done/')
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>(r'^contact/$', ContactWizard([ContactForm1, ContactForm2])),
  </code></pre>
  
  <hr>
  
  <p>Separately I have inlines being generated into another form. I'm doing this via <strong>inlineformset_factory</strong> in my view. <strong>This is not connected to the formwizard example above.</strong> This is an ingredients to recipes example.
  I'm doing this like:</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def add(request):
      IngredientFormSet = inlineformset_factory(Recipe, Ingredient, 
                  fk_name="recipe", 
                  formfield_callback=curry(ingredient_form_callback, None))
  
      if request.method == 'POST':
          form = RecipeForm(request.POST)
          formset = IngredientFormSet(request.POST)
          if form.is_valid() and formset.is_valid():
              recipe = form.save()
              formset = IngredientFormSet(request.POST, instance=recipe)            
              formset.save()
              return redirect("/edit/%s" % recipe.id)
      else:
          form = RecipeForm()
          formset = IngredientFormSet()
  
      return render_to_response("recipes_add.html", {"form":form, "formsets":formset}, context_instance=RequestContext(request))
  </code></pre>
  
  <p><strong>recipes_add.html</strong></p>
  
  <pre><code>&lt;form method="post"&gt;
  {% csrf_token %}
      &lt;table&gt;
      {{ form }}
      &lt;/table&gt;
      &lt;hr&gt;
      &lt;h3&gt;Ingredients&lt;/h3&gt;
      &lt;div class="inline-group"&gt;
        &lt;div class="tabular inline-related last-related"&gt;
            {{ formsets.management_form }}
            {% for formset in formsets.forms %}
            &lt;table&gt;
                {{ formset }}
            &lt;/table&gt;
            {% endfor %}
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;p class="success tools"&gt;&lt;a href="#" class="add"&gt;Add another row&lt;/a&gt;&lt;/p&gt;
      &lt;input type="submit" value="Add"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>How can I get the inlines to work within my formwizard multistep form?</strong>
  The <strong>models.py</strong> now looks like this because <strong>I want books to be inlines to contact</strong>. I want the inlines to be on the first step of my formwizard. Then go through to step 2 and finish.</p>
  
  <pre><code>from django.db import models
  
  # Create your models here.
  class Contact(models.Model):
      subject = models.CharField(max_length=50)
      sender = models.EmailField()
  
      def __unicode__(self):
          return self.subject
  
  class Contact2(models.Model):
      message = models.TextField(max_length=500)
  
      def __unicode__(self):
          return self.message
  
  class Book(models.Model):
     author = models.ForeignKey(Contact)
     title = models.CharField(max_length=100)
  </code></pre>