title: Validate django inline formset
body: <p>i have used django inline formset so make a single crud on two models.
  Unlike a django form,<strong>django formset</strong> works with multiple forms at a time.So its really confusing for me to validate django formset.but i need to validate my django formset.I really i hasn't found any solution yet.</p>
  
  <p>I have two models namely <strong>Discount</strong> and <strong>Discount products</strong>.I have used django formset for <strong>discount products formsets</strong> among with <strong>discount form</strong>.</p>
  
  <p>By default formsets allows user to avoid all the form when creating a new instance or update a new instance,which actually make sense,because there can be 15 or 20 forms.In my system , i am also following the same way.</p>
  
  <p>In my <strong>discount formsets</strong>, there are two fields namely <code>primary variant</code> and <code>variants</code>.</p>
  
  <p>If user don't fill up any field of any forms of the formsets,he can do it and can create or update only <strong>discount form</strong> object,which is fine.(remember <strong>discount form</strong> is reside above the <strong>discount products formsets</strong>).</p>
  
  <p>but if he fill only <code>variant</code> field and emty the <code>primary variant</code> field ,then the user should not allow to do this,because in my system ,a <code>variant</code> can not be created or updated without <code>primary variant</code>.But in this  point i can't validating it.Because its a formsets.I really need idea how to do this type of validation.</p>
  
  <p>here is he <strong>Create view</strong> where i am combining the <strong>discount</strong> and <strong>discount products</strong>.(Providing only the create view, i hope solution will be same for the update view also)</p>
  
  <pre><code>class DiscountCreate(RequestPassingFormViewMixin, WammuCreateView):
      model = Discount
      template_name = 'dashboard/discount_form.html'
      form_class = DiscountForm
  
      def get_form_kwargs(self, *args, **kwargs):
          kwargs = super(DiscountCreate, self).get_form_kwargs(*args, **kwargs)
          common = get_object_or_404(Common, pk=self.kwargs['common_pk'])
          discount = Discount(common=common)
          kwargs['instance'] = discount
          return kwargs
  
      def get(self, request, *args, **kwargs):
          self.object = None
          form_class = self.get_form_class()
          form = self.get_form(form_class)
          DiscountProductInlineFormSet = inlineformset_factory(Discount, DiscountProducts,
                                                          form=DiscountProductForm,
                                                          can_delete=True, extra=5)
          DiscountProductInlineFormSet.form = staticmethod(curry(DiscountProductForm, request=request))
          discount_product_formset = DiscountProductInlineFormSet(instance=self.object)
          return self.render_to_response(
          self.get_context_data(form=form, discount_formset=discount_product_formset))
  
     def post(self, request, *args, **kwargs):
          self.object = Discount()
          form = self.get_form(self.form_class)
          DiscountProductInlineFormSet = inlineformset_factory(Discount, DiscountProducts,
                                                          form=DiscountProductForm,
                                                          can_delete=True, extra=5)
          DiscountProductInlineFormSet.form = staticmethod(curry(DiscountProductForm, request=request))
          if form.is_valid():
              self.object = form.save(commit=False)
          else:
              discount_product_formset = DiscountProductInlineFormSet(request.POST,
                                                                instance=self.object)
              return self.render_to_response(
              context=self.get_context_data(form=form, discount_formset=discount_product_formset))
  
          promotion_product_formset = DiscountProductInlineFormSet(request.POST, instance=self.object)
          if discount_product_formset.is_valid():
              self.object.save()
              discount_product_formset.save()
              return super(Discountreate, self).form_valid(form)
          else:
              return self.render_to_response(
                  context=self.get_context_data(form=form, discount_formset=discount_product_formset))
  </code></pre>
  
  <p>and this is my forms where both <strong>Discount</strong> and <strong>Disount Products</strong> resides,</p>
  
  <pre><code>class DiscountForm(RequestPassingFormMixin, ModelForm):
      class Meta:
          model = Discount
  
      def __init__(self, *args, **kwargs):
          super(PromotionForm, self).__init__(*args, **kwargs)
          common = Chain.objects.get(pk=self.request.session.get('chain_pk'))
  
      class DiscountProductForm(autocomplete_light.ModelForm):    
          class Meta:
              model = DiscountProducts
              fields = ['code', 'variants', 'primary_variant']
  
      def __init__(self, *args, **kwargs):
          self.request = kwargs.pop("request")
          super(DiscountProductForm, self).__init__(*args, **kwargs)
          common = Chain.objects.get(pk=self.request.session.get('common_pk'))
          self.fields['variants'].queryset = Variant.objects.filter(product__common__pk=common.pk)
          self.fields['primary_variant'].queryset = Variant.objects.filter(product__common__pk=common.pk) 
  </code></pre>