title: Django - Checkboxes & ManytoMany relationships in TemplateView
body: <p>I have a app where users can register their company and then select a number of settings from a list. Both the company and services are different models. </p>
  
  <pre><code>class Company(models.Model):
      name = models.CharField(max_length=100)
      (...)
  
  class Service(models.Model):
      name = models.CharField(max_length=100)
      linked_companies = ManyToManyField(Company, blank=True)
  </code></pre>
  
  <p>What I want is to have a large list of services, with checkboxes behind their names, so the owner can quickly select the services that he wants to connect to his model. This used to be done through the admin interface, but due popular demand this feature is moved to 'the front'. </p>
  
  <p>The problem is that I do not know how to fit this into the traditional (generic) view/form combinations that we' ve been using so far, since two different models are involved. </p>
  
  <p>I am trying a more custom solution, but have hit a wall and I am wondering if you could help me. I have created a html page that should display both the list of services and a 'save' button. </p>
  
  <pre><code>&lt;form action="." method="POST" class="post-form"&gt;{% csrf_token %}
          &lt;ul&gt;
          {% recursetree services %}
              &lt;li&gt;
                  &lt;label&gt;&lt;input type="checkbox" name='service' value={{ node.pk }}&gt;&lt;h3&gt;{{ node.name }}&lt;/h3&gt;&lt;/label&gt;
                  {% if not node.is_leaf_node %}
                      &lt;ul class="children"&gt;
                          {{ children }}
                      &lt;/ul&gt;
                  {% endif %}
              &lt;/li&gt;
          {% endrecursetree %}
          &lt;/ul&gt;
  
          &lt;button type="submit" class="save btn btn-default"&gt;Add Selected
          &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I am using the following ModelForm:</p>
  
  <pre><code>class FacetForm(forms.ModelForm):
      class Meta:
          model = Services
          fields = ['linked_tenants', 'name']
  
          widgets = {
              'linked_tenants' : CheckboxSelectMultiple()
          }
  </code></pre>
  
  <p>This HTML page seems to work as intended, showing a long list of services with checkboxes after their names. 
  However, I have trouble creating a function view. Together with a collegue the following view was created </p>
  
  <p>class FacetList(TenantRootedMixin, TemplateView):</p>
  
  <pre><code>def get_context_data(self, **kwargs):
      d = super(ServiceList, self).get_context_data(**kwargs)
      d['services'] = Services.objects.all()
      d['current_company'] = self.context.company.id
      return d
  
  def form_valid(self, *args, **kwargs):
      return super(ServiceList, self).form_valid(*args, **kwargs)
  </code></pre>
  
  <p>This view works in the sense that it shows all of the relevant information (with the checkboxes). If I change the query to filter the services by 'company id'. the view works as desired as well. </p>
  
  <p>The problems I have revolve around the fact that pressing 'save'. crashes the program, throwing the following error.  </p>
  
  <pre><code>'super' object has no attribute 'post'
  </code></pre>
  
  <p>Our program works mostly through generic classbased views and modelforms, so we have relativly limited experience with creating our own custom solutions. By my own estimation the problem seems to be twofold:</p>
  
  <ol>
  <li>The view is probably not configured right to process the 'post' data</li>
  <li>It is questionable if the data will be processed to the database afterwards. </li>
  </ol>
  
  <p>Though are 'sollution' is currently flawed, are we looking in the right direction? Are we on the right way to solve our problem? </p>
  
  <p>Regards</p>