title: Django Inline Formset Inside Model Formset
body: <p>i have two models named product and productimage .I will have multiple </p>
  
  <p>images for product. So in this application, i want to create multiple </p>
  
  <p>products and each products i want to create multiple images in a single </p>
  
  <p>form using modelformset_factory and inlineformset_factory. i tried, but </p>
  
  <p>it was not success. how can i do that. </p>
  
  <p>here product is a modelformset and productimage is an inlineformset</p>
  
  <pre><code>models.py :
  
  
  class Product(models.Model):
      title = models.CharField(max_length=128)
      description = models.TextField()
      image = models.ImageField(upload_to="images/")
  
      def __unicode__(self):
          return self.title
  
  
  class ProductImage(models.Model):
      product = models.ForeignKey(Product, related_name="%(app_label)s_%(class)s")
      title = models.CharField(max_length=128)
      image = models.ImageField(upload_to="images/")
  
      def __unicode__(self):
          return self.title
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>Product_modelformset = modelformset_factory(Product, form=ProductForm, extra=0, min_num=1)
  
  Productimage_inlineformset = inlineformset_factory(Product, ProductImage, form=ProductImageForm, extra=0,
                                                      min_num=1, max_num=5, can_delete=True)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def create_product(request):
      template = "frontend/create_product.html"
  context = {}
  
  product_formset = Product_modelformset(queryset=Product.objects.none(), prefix="product_formset")
  
  productimage_formset = Productimage_inlineformset(prefix="productimage_formset")
  
  if request.method == 'POST':
      pass
  ........
  .........
  
  context["product_formset"] = product_formset
  context["productimage_formset"] = productimage_formset
  
  return render(request, template, context)
  </code></pre>
  
  <p>create_product.html</p>
  
  <pre><code>{% for form in product_formset.forms %}
          &lt;div class="form_items"&gt;
              &lt;p class="lead"&gt;Product ITems&lt;/p&gt;
              {{ form.as_p }}
          &lt;/div&gt;
          {% for form in productimage_formset.forms %}
          &lt;div class="image_items"&gt;
              &lt;p class="lead"&gt;image items&lt;/p&gt;
              {{ form.as_p }}
          &lt;/div&gt;
          {% endfor %}
   {% endfor %}
  
    &lt;script&gt;
          $(document).ready(function() {
              $('div.form_items').formset({
                  prefix: "{{ product_formset.prefix }}"
              });
              $('div.image_items').formset({
                  prefix: "{{ productimage_formset.prefix }}"
              });
          });
      &lt;/script&gt;
  </code></pre>