title: Django select multiple objects and save user choices
body: <p>I need help getting user preferences to save to the db. I have a set of community objects defined by the following model:</p>
  
  <pre><code>class Community(models.Model):
      name = models.CharField(max_length=20, unique=True)
      banner = models.ImageField(upload_to="communityBanners", blank=True)
      creation_date = models.DateTimeField(default=timezone.now)
  </code></pre>
  
  <p>Each user has a profile that looks like the following:</p>
  
  <pre><code>class UserProfile(models.Model):
      user = AutoOneToOneField(settings.AUTH_USER_MODEL, primary_key=True,
                               on_delete=models.CASCADE)
      points = models.DecimalField(default=0.0, max_digits=10, decimal_places=2)
      credScore = models.DecimalField( default=0.0, max_digits=4, decimal_places=2 )
      website = models.URLField(blank=True)
      avatar = models.ImageField(upload_to="profilePics", blank=True)
  
      community_preferences = models.ManyToManyField(Community)
  </code></pre>
  
  <p>I've made it so that users are able to create new communities. However, I want to also make it so that other users can go to a multiple choice form and select which communities they want to join, then hit submit and store the preferences. Since the communities are objects, how do I create a multiple choice object field and form that they can select those and then save their preferences? </p>
  
  <p>Could someone help show me how to structure the following: form, html template to display the options, and how to properly save the preferences? </p>
  
  <p>I'm under the impression that ModelChoiceField will not work here since I want to be able to select one, all, or any number in between of objects.</p>
  
  <p>EDIT:</p>
  
  <p>Here is the new form: </p>
  
  <pre><code>class CommunitySelectForm(forms.Form):
      communities = forms.ModelMultipleChoiceField(queryset=Community.objects.all(), widget=forms.CheckboxSelectMultiple)
  </code></pre>
  
  <p>Here is my view: </p>
  
  <pre><code>def joinCommunities(request, user_id):
      #user_ob = get_user_model().objects.filter(id=user_id).first()
      #full_user_profile = UserProfile.objects.filter(user=user_ob).first()
  
      if request.method == 'POST':
          form = CommunitySelectForm(request.POST)
          if form.is_valid():
              comms = form.save(commit=False)
              comms.user = request.user
              comms.save()
      else:
          form = CommunitySelectForm()
      print(form)
      return render(request, 'qa/select_communities.html', {'form' : form})
  </code></pre>
  
  <p>And here is the template that doesn't seem to be loading anything:</p>
  
  <pre><code>{% extends 'qa/base.html' %}
  {% load staticfiles %}
  {% load gravatar %}
  {% block content %}
  
  &lt;div&gt;
      &lt;div class="col-sm-8 input"&gt;
        &lt;form method="post" enctype='multipart/form-data'&gt;
            {% csrf_token %}    
              {% for field in form %}
                  &lt;div class="form-group"&gt;
                      &lt;div class="col-sm-offset-2 col-sm-10"&gt;
  
  
                          &lt;span class="text-danger small"&gt;{{ field.errors }}&lt;/span&gt;
                      &lt;/div&gt;
                      &lt;label class = "control-label col-sm-2"&gt;{{ field.label_tag }}&lt;/label&gt;
                      &lt;div class="col-sm-10"&gt;{{ field }}&lt;/div&gt;
                  &lt;/div&gt;
              {% endfor %}
            &lt;input class="btn btn-submit pull-right" href="/profile/{{ user.id }}" type="submit" value="Choose Communities" /&gt;
        &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  {% endblock content %}
  </code></pre>
  
  <p>I've also set up the URL for joining the communities as follows:</p>
  
  <pre><code> url(r'^join-communities/(?P&lt;user_id&gt;\d+)/$', views.joinCommunities, name='qa_join_communities')
  </code></pre>
  
  <p>The issue is that when I submit the form it doesn't save and I get this error:</p>
  
  <pre><code>'CommunitySelectForm' object has no attribute 'save'
  </code></pre>