title: Django form with two models
body: <p>Now i want create form in which I could edit both models ( I want display cart with products and have possibility to edit price of every product from this cart). I used inlineformset_factory but it displays error. I use this way first time so I have no idea what must I change.</p>
  
  <blockquote>
    <p>'shop.Product' has no ForeignKey to 'shop.Cart'.</p>
  </blockquote>
  
  <p>models.py</p>
  
  <pre><code>class Product(models.Model):
      name = models.CharField(max_length=100)
      price = models.IntegerField(default='0')
  
      def __unicode__(self):
          return u"{}({})".format(self.name, self.price)
  
  class Cart(models.Model):
      product = models.ManyToManyField(Product)
      name = models.CharField(max_length=50)
  
      def __unicode__(self):
          return self.name
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class CartForm(forms.ModelForm):
      product = forms.ModelMultipleChoiceField(queryset = Product.objects.all(), widget=forms.CheckboxSelectMultiple(),required=True) 
      name = forms.CharField(max_length=45, label='nazwa')
      price = forms.IntegerField(label='price')
  
      class Meta: 
          model = Cart
          fields = ('product', 'name', 'price')
  
  IngredientFormSet = inlineformset_factory(Cart, Product)
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def cart_new(request):
      if request.method == "POST":
          form = CartForm(request.POST)
          if form.is_valid():
              cart = form.save(commit=False)
              cart.save()
              form.save_m2m()
              ingredient_formset = IngredientFormSet(request.POST)
              if ingredient_formset.is_valid():
                  ingredient = formset.save(commit=False)
                  ingredient_formset.save()
                  return redirect('shop.views.cart_detail', pk=cart.pk)
      else:
          form = CartForm()
      return render(request, 'shop/cart_edit.html', {'form': form})
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>    Traceback:
  File "C:\Users\znawca\myapp\venv\lib\site-packages\django\core\handlers\base.py" in get_response
    119.                 resolver_product = resolver.resolve(request.path_info)
  File "C:\Users\znawca\myapp\venv\lib\site-packages\django\core\urlresolvers.py" in resolve
    366.             for pattern in self.url_patterns:
  File "C:\Users\znawca\myapp\venv\lib\site-packages\django\core\urlresolvers.py" in url_patterns
    402.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\znawca\myapp\venv\lib\site-packages\django\core\urlresolvers.py" in urlconf_module
    396.             self._urlconf_module = import_module(self.urlconf_name)
  File "D:\Python27\Lib\importlib\__init__.py" in import_module
    37.     __import__(name)
  File "C:\Users\znawca\myapp\league\league\urls.py" in &lt;module&gt;
    6.     url(r'', include('shop.urls')),
  File "C:\Users\znawca\myapp\venv\lib\site-packages\django\conf\urls\__init__.py" in include
    33.         urlconf_module = import_module(urlconf_module)
  File "D:\Python27\Lib\importlib\__init__.py" in import_module
    37.     __import__(name)
  File "C:\Users\znawca\myapp\league\shop\urls.py" in &lt;module&gt;
    2. from . import views
  File "C:\Users\znawca\myapp\league\shop\views.py" in &lt;module&gt;
    2. from .forms import *
  File "C:\Users\znawca\myapp\league\shop\forms.py" in &lt;module&gt;
    19. IngredientFormSet = inlineformset_factory(Cart, Product)
  File "C:\Users\znawca\myapp\venv\lib\site-packages\django\forms\models.py" in inlineformset_factory
    1020.     fk = _get_foreign_key(parent_model, model, fk_name=fk_name)
  File "C:\Users\znawca\myapp\venv\lib\site-packages\django\forms\models.py" in _get_foreign_key
    992.                     parent_model._meta.object_name,
  
  Exception Type: ValueError at /
  Exception Value: 'shop.Product' has no ForeignKey to 'shop.Cart'.
  </code></pre>