title: Initial Data for Django Inline Formsets
body: <p>I have put together a form to save a recipe.  It makes use of a form and an inline formset.  I have users with text files containing recipes and they would like to cut and paste the data to make entry easier.  I have worked out how to populate the form portion after processing the raw text input but I cannot figure out how to populate the inline formset.</p>
  
  <p>It seems like the solution is almost spelled out here:  <a href="http://code.djangoproject.com/ticket/12213" rel="noreferrer">http://code.djangoproject.com/ticket/12213</a> but I can't quite put the pieces together.</p>
  
  <p>My models:</p>
  
  <pre><code>#models.py
  
  from django.db import models
  
  class Ingredient(models.Model):
      title = models.CharField(max_length=100, unique=True)
  
      class Meta:
          ordering = ['title']
  
      def __unicode__(self):
          return self.title
  
      def get_absolute_url(self):
          return self.id
  
  class Recipe(models.Model):
      title = models.CharField(max_length=255)
      description = models.TextField(blank=True)
      directions = models.TextField()
  
      class Meta:
          ordering = ['title']
  
      def __unicode__(self):
          return self.id
  
      def get_absolute_url(self):
          return "/recipes/%s/" % self.id
  
  class UnitOfMeasure(models.Model):
      title = models.CharField(max_length=10, unique=True)
  
      class Meta:
          ordering = ['title']
  
      def __unicode__(self):
          return self.title
  
      def get_absolute_url(self):
          return self.id
  
  class RecipeIngredient(models.Model):
      quantity = models.DecimalField(max_digits=5, decimal_places=3)
      unit_of_measure = models.ForeignKey(UnitOfMeasure)
      ingredient = models.ForeignKey(Ingredient)
      recipe = models.ForeignKey(Recipe)
  
      def __unicode__(self):
          return self.id
  </code></pre>
  
  <p>The recipe form is created using a ModelForm:</p>
  
  <pre><code>class AddRecipeForm(ModelForm):
      class Meta:
          model = Recipe
          extra = 0
  </code></pre>
  
  <p>And the relevant code in the view (calls to parse out the form inputs are deleted):</p>
  
  <pre><code>def raw_text(request):
      if request.method == 'POST':
  
      ...    
  
          form_data = {'title': title,
                      'description': description,
                      'directions': directions,
                      }
  
          form = AddRecipeForm(form_data)
  
          #the count variable represents the number of RecipeIngredients
          FormSet = inlineformset_factory(Recipe, RecipeIngredient, 
                           extra=count, can_delete=False)
          formset = FormSet()
  
          return render_to_response('recipes/form_recipe.html', {
                  'form': form,
                  'formset': formset,
                  })
  
      else:
          pass
  
      return render_to_response('recipes/form_raw_text.html', {})
  </code></pre>
  
  <p>With the FormSet() empty as above I can successfully launch the page.  I have tried a few ways to feed the formset the quantity, unit_of_measure and ingredients I have identified including:</p>
  
  <ul>
  <li>setting initial data but that doesn't work for inline formsets</li>
  <li>passing a dictionary, but that generates management form errors</li>
  <li>played around with <strong>init</strong> but I'm a bit out of my depth there</li>
  </ul>
  
  <p>Any suggestions greatly appreciated.</p>