title: How to instantiate FormSet with objects
body: <p>I tried looking in <a href="https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#changing-the-queryset" rel="nofollow">Django Docs</a> to see if I could find a similar parameter to instance in ModelForm but I could not make it work.</p>
  
  <pre><code>class RequiredFormSet(BaseFormSet):
      def __init__(self, *args, **kwargs):
          super(RequiredFormSet, self).__init__(*args, **kwargs)
          for form in self.forms:
              form.empty_permitted = False
  
  OfferItemFormSet = formset_factory(OfferItemForm, formset=RequiredFormSet)
  </code></pre>
  
  <h1>Forms.py</h1>
  
  <pre><code>class OfferItemForm(ModelForm):
  
  class Meta:
      model = OfferItem
      exclude = ('offer', 'item_code', 'type')
      [...]
  </code></pre>
  
  <h1>Views.py</h1>
  
  <pre><code>i = OfferItem.objects.filter(offer=o).values()
  item_formset = OfferItemFormSet(queryset=i)
  </code></pre>
  
  <p>I always <code>__init__() got an unexpected keyword argument 'queryset'</code>. I tried to change from formset_factory to modelformset_factory but still the same problem.</p>
  
  <pre><code>Traceback:
  File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/core/handlers/base.py" in get_response
    132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Library/Python/2.7/site-packages/Django-1.8.3-py2.7.egg/django/contrib/auth/decorators.py" in _wrapped_view
    22.                 return view_func(request, *args, **kwargs)
  File "[...]/filter_decorators.py" in _wrapped_view
    13.                 return a_view(request, *args, **kwargs)
  File "[...]/views.py" in manage_offer
    1330.         item_formset = OfferItemFormSet(queryset=i)
  File "[...]/forms.py" in __init__
    197.             super(RequiredFormSet, self).__init__(*args, **kwargs)
  
  Exception Type: TypeError at /my/offer/add/
  Exception Value: __init__() got an unexpected keyword argument 'queryset'
  </code></pre>
  
  <p>Why is it such a big deal? Why isn't there an instance= parameter on the constructor method of the formset just like a ModelForm has?</p>
  
  <h1>Edit: Using modelformset_factory()</h1>
  
  <pre><code>OfferItemFormSet = modelformset_factory(OfferItem, form=OfferItemForm, formset=RequiredFormSet)
  </code></pre>
  
  <h1>Forms.py</h1>
  
  <pre><code>from django.forms.models import modelformset_factory
  
  class RequiredFormSet(BaseFormSet):
      def __init__(self, *args, **kwargs):
          super(RequiredFormSet, self).__init__(*args, **kwargs)
          for form in self.forms:
              form.empty_permitted = False
  </code></pre>
  
  <h1>Views.py</h1>
  
  <pre><code>i = OfferItem.objects.filter(offer=o)
  item_formset = OfferItemFormSet(queryset=i)
  
  __init__() got an unexpected keyword argument 'query set'
  Exception Location: [...]/forms.py in __init__, line 198
  </code></pre>
  
  <h1>Resolution</h1>
  
  <p>After changing <code>BaseFormSet</code> to <code>BaseModelFormSet</code> AND adding <code>{{ form.id }}</code> to my loop when generating the formset in the template.</p>