title: how to set default values for manytomanyfield
body: <p>Is there a way around the "instance needs to have a primary key value before a many-to-many relationship can be used" error?</p>
  
  <p>I have a model with several fields including a many-to-many relationship to another model.  I have a function to set default values on those fields when I am creating a new instance of the model.  I do this in the view when handling an HTTP GET.  The m2m field gets rendered using a formset.</p>
  
  <p>Here is some pseudo-code describing the situation:</p>
  
  <pre><code>class MyRelatedModel(models.Model):
    name = models.CharField(max_length=100,blank=True)
  
  class MyModel(models.Model):
    name = models.CharField(max_length=100,blank=True)
    relatedModels = models.ManyToManyField("MyRelatedModel")
  
    def initialize(self):
      self.name = "my default name"
      # this bit doesn't really matter...
      # just assume I am creating a new set of RelatedModels that I want to associate with my this new MyModel...
      newRelatedModels = []
      for name in ["related model 1", "related model 2", "related model 3"]:
        relatedModel = MyRelatedModel(name=name)
        relatedModel.save()
        newRelatedModels.append(relatedModel.id)
      self.relatedModels = newRelatedModels # this is invalid!
  
  def MyView(request):
    if request.method == 'GET':
      model = MyModel()
      model.initialize()
      form = MyForm(instance=model)
    return render_to_response("my_template.html", {"form" : form}, context_instance=RequestContext(request))
  </code></pre>
  
  <p>Any suggestions?        </p>
  
  <p>I suspect that I may need to handle this on the form side rather than the model side, but that's confusing me too.</p>