title: django ModelForm save issue with ManyToManyField
body: <p>I'm new to Django and was needing some help on a view error i am getting. </p>
  
  <p>I wrote a view that will display a data table of "Groups" if the request method is GET, or display a form to edit a particular "Group" if the request method is POST (item to edit is passed with POST data).  </p>
  
  <p>Also, if POST on an existing item, i'd like the form to be pre-populated with the data i already have in the table for that item.  I've pretty much got it all down, except when i goto save an edited form, i keep getting this error:</p>
  
  <p>"Cannot set values on a ManyToManyField which specifies an intermediary model"</p>
  
  <p>Any help would be greatly appreciated.  Also, I'm new to all this web dev stuff, so if i'm doing something completely silly or am missing a concept, please feel free to flame me accordingly.  ;-)</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>class Alias(models.Model):
      def __unicode__(self):
          return unicode(self.alias)
      alias = models.CharField(max_length=32)
  
  class Octet(models.Model):
      def __unicode__(self):
          return unicode(self.num)
      num = models.IntegerField(max_length=3)
  
  class Group(models.Model):
      def __unicode__(self):
          return unicode(self.name)
      name = models.CharField(max_length=32) #name of the group
      id = models.AutoField(primary_key=True) #primary key
      octets = models.ManyToManyField(Octet, through='OctetAssignment', blank=True) #not required
      aliases = models.ManyToManyField(Alias, through='AliasAssignment', blank=True) #not required
  
  class OctetAssignment(models.Model):
      octet = models.ForeignKey(Octet) #octet
      group = models.ForeignKey(Group) #group that octet is assigned to
  
  class AliasAssignment(models.Model):
      alias = models.ForeignKey(Alias)
      group = models.ForeignKey(Group)
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>def index(request):
      if request.method == 'GET':
          groups = Group.objects.all().order_by('name')
          return render_to_response('groups.html', 
                                    { 'groups': groups, }, 
                                    context_instance = RequestContext(request),
                                    )
  
      elif request.method == "POST":
          g = Group.objects.get(id=request.POST['id'])
          form = GroupEditForm(instance=g)
          return render_to_response('groups.html',
                                   { 'form': form,  },
                                   context_instance = RequestContext(request),
                                   )
  
  def save(request):
      if request.method == "POST":
          form = GroupEditForm(request.POST)
          if form.is_valid():
              form.save()
  
          return HttpResponseRedirect('/tradedesk/groups/') # Redirect after POST
  </code></pre>
  
  <p>To make it complete, here is the form template code i'm using that renders the table and edit page.
  <strong>Template</strong>
      </p>
  
  <pre><code>    &lt;h1&gt;Group Information&lt;/h1&gt;
  
      {% if groups %}
          &lt;table border=1&gt;
  
          {% for group in groups %}
  
          &lt;tr&gt;
  
          &lt;td&gt;{{group.name}}&lt;/td&gt;
  
          &lt;td&gt;{% for octet in group.octets.all %} {{octet}} {% endfor %}&lt;/td&gt;
  
          &lt;td&gt;{% for alias in group.aliases.all %} {{alias}} {% endfor %}&lt;/td&gt;
  
          &lt;td&gt;{{group.analyst}}&lt;/td&gt;
  
          &lt;/tr&gt;
  
          {% endfor %}
  
          &lt;/table&gt;
      &lt;br&gt;&lt;/br&gt;
  
      &lt;form method="post" action="/groups/"&gt;{% csrf_token %}
      &lt;select name="id" &gt;
          {% for group in groups %}
          &lt;option value="{{group.id}}"&gt;{{group.name}}&lt;/option&gt;
          {% endfor %}
      &lt;/select&gt;
      &lt;input type="submit" value="Edit"&gt;
  
      &lt;/form&gt;
      {% endif %}
  
  
      {% if form %}
      &lt;form method="post" action="/groups/save/"&gt;{% csrf_token %}
  
          {{form}}
      &lt;br&gt;&lt;/br&gt;
      &lt;input type="submit" value="Save"&gt;
      &lt;form&gt;
  
      {% endif %}
  
  
  
  &lt;/div&gt;
  </code></pre>