title: Saving form with m2m relationship not saving to database
body: <p>I am trying to save a multiple select check box form using a m2m structure, but my values are not being saved to the database.</p>
  
  <p>I have a State and Options. A State can have multiple Options and Options can have multiple states. In practice, I want to save multiple options for each state and then save the connections in the intermediate StateOption table. There is no error produced but when I check my database, nothing has been saved.</p>
  
  <p>Also, if you see anything wrong with the way I set up my database structure, feel free to comment. I am new to databases and django.</p>
  
  <p>models.py</p>
  
  <pre><code>class Option(models.Model):
      relevantdisease = models.ForeignKey(Disease)
      option = models.CharField(max_length=255)
  
  class State(models.Model):
     state = models.CharField(max_length=255)
     relevantdisease = models.ForeignKey(Disease)
     relevantoption = models.ManyToManyField(Option, blank=True, through='StateOption')
  
  #intermediate table may not be needed
  class StateOption(models.Model):
     state_table = models.ForeignKey(State)
     option_table = models.ForeignKey(Option)
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class StateOptionForm(forms.ModelForm):
      option_choices = forms.ModelMultipleChoiceField(queryset=Option.objects.all(), required=False, widget=forms.CheckboxSelectMultiple)
  
      class Meta:
         model = State #StateOption if I use the intermediate table
         exclude = ['state_table', 'option_table']
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def stateoption(request, disease_id, state_id):
  
      state = get_object_or_404(State, pk=state_id)
      disease = get_object_or_404(Disease, pk=disease_id)
  
      if request.method == "POST":
          form = StateOptionForm(request.POST, instance=state)
  
          if form.is_valid():
             profile = form.save(commit=False)
             profile.user = request.user
             profile.save()    #this and the line below is probably where the problem is
             form.save_m2m()   
  
  
             #stateoption = StateOption.objects.create(state_table=state, option_table=profile)   &lt;--produces an error saying that the instance needs to be Option
  
             return HttpResponseRedirect(reverse('success'))
  
      else:
          form = StateOptionForm(instance=state)
  
  
      context = {'state': state, 'disease':disease, 'option': form }
      return render(request, "stateoption.html", context)
  </code></pre>
  
  <p><strong>Update</strong>
  An intermediate table is probably not needed for this use case, but it will be needed as I add more complexity to this problem. Is there a way to save this form to the database with an intermediate table?</p>