title: 'QueryDict' object has no attribute
body: <p>I am trying to assign members to group (Unit), but I get 'QueryDict' object has no attribute error on POST.</p>
  
  <p>If request isn't a POST, the form renders as it should, giving me a Name field for the group (Unit) and a multiple select with users is this clan. But if request is POST, it gives me error.</p>
  
  <p>I am sure there are more issues with this code and I will appreciate a detailed answer, because I am new to Django and Python. Thank you in advance.</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class ClanProfile(models.Model):
      tag = models.CharField(max_length=12, unique=True)
      url = models.SlugField(max_length=12, unique=True, help_text="URL of your clan", db_index=True)
      owner = models.ForeignKey(User)
  
      members = models.ManyToManyField(User, through='Membership', related_name='clan_members', through_fields=('clan', 'user'))
  
      def __unicode__(self):
          return self.tag
  
  
  class Unit(models.Model):
      name = models.CharField(max_length=64)
      clan = models.ForeignKey(ClanProfile)
      members = models.ManyToManyField(User, through='Membership', related_name='unit_members', through_fields=('unit', 'user', 'clan'))
      def __unicode__(self):
          return self.name
  
  class Membership(models.Model):
      user = models.ForeignKey(User)
      clan = models.ForeignKey(ClanProfile)
      unit = models.ForeignKey(Unit, blank=True, null=True)
      date_joined = models.DateField(blank=True, auto_now_add=True)
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>@login_required
  def AddUnit(request, url):
      clan = get_object_or_404(ClanProfile, url=url)
      if clan.owner != request.user:
          return HttpResponse('&lt;strong&gt;You are not the owner of this clan!&lt;/strong&gt;')
      if request.method == 'POST':
          form = AddUnitForm(request.POST, clan)
          if form.is_valid():
              submission = form.save(commit=False)
              submission.clan = clan
              submission.save()
              return HttpResponseRedirect("/%s" % clan.url)
      else:
          form = AddUnitForm(clan)
      return render(request, 'app/add_unit.html', {'form': form})
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class AddUnitForm(ModelForm):
      def __init__(self, clan, *args, **kwargs):
          super(AddUnitForm, self).__init__(*args, **kwargs)
          self.fields['members'] = forms.ModelMultipleChoiceField(queryset=clan.members, label='Assign members', )
      class Meta:
          model = Unit
          exclude = ['clan']
  </code></pre>
  
  <p><strong>Traceback:</strong></p>
  
  <pre><code> Environment:
  
  
  Request Method: POST
  Request URL: http://127.0.0.1:8000/41/add-unit/
  
  Django Version: 1.8.3
  Python Version: 2.7.10
  Installed Applications:
  ('django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'app')
  Installed Middleware:
  ('django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware',
   'django.middleware.security.SecurityMiddleware')
  
  
  Traceback:
  
      File "D:\django\project\env\lib\site-packages\django\core\handlers\base.py" in get_response
        132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "D:\django\project\env\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
        22.                 return view_func(request, *args, **kwargs)
      File "D:\django\project\app\views.py" in AddUnit
        85.         form = AddUnitForm(request.POST, clan)
      File "D:\django\project\app\forms.py" in __init__
        16.         self.fields['members'] = forms.ModelMultipleChoiceField(queryset=clan.members, label='Assign members', )
  
      Exception Type: AttributeError at /41/add-unit/
      Exception Value: 'QueryDict' object has no attribute 'members'
  </code></pre>