title: Adding a specific quantity of the product to the cart in django
body: <p>I have a problem because I have no idea how to implement 'adding a specific amount of product to cart'.
  Currently, after pressing the 'Add to cart' button, a single quantity of product is added. </p>
  
  <p>I don't know how to relate to this in the view and the template.</p>
  
  <p>I would like it to take the value given instead of 1.</p>
  
  <pre><code>cart_item.quantity += 1
  </code></pre>
  
  <p><strong>cart/views.py</strong></p>
  
  <pre><code>def add_cart(request, product_id):
      product = Product.objects.get(id=product_id)
      try:
          cart = Cart.objects.get(cart_id=_cart_id(request))
      except Cart.DoesNotExist:
          cart = Cart.objects.create(
                  cart_id = _cart_id(request)
              )
          cart.save()
      try:
        cart_item = CartItem.objects.get(product=product, cart=cart)
        if cart_item.quantity &lt; cart_item.product.stock:
            cart_item.quantity += 1
        cart_item.save()
      except CartItem.DoesNotExist:
        cart_item = CartItem.objects.create(
                    product = product,
                    quantity = 1,
                    cart = cart
            )
        cart_item.save()
      return redirect('cart:cart_detail')
  </code></pre>
  
  <p><strong>cart/models.py</strong></p>
  
  <pre><code>class Cart(models.Model):
      cart_id = models.CharField(max_length=250, blank=True)
      date_added = models.DateField(auto_now_add=True)
      class Meta:
          db_table = 'Cart'
          ordering = ['date_added']
  
      def __str__(self):
          return self.cart_id
  
  class CartItem(models.Model):
      product = models.ForeignKey(Product, on_delete=models.CASCADE)
      cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
      quantity = models.IntegerField()
      active = models.BooleanField(default=True)
      class Meta:
          db_table = 'CartItem'
  
      def sub_total(self):
          return self.product.price * self.quantity
  
      def __str__(self):
          return self.product
  </code></pre>
  
  <p><strong>templates/shop/product.html</strong></p>
  
  <pre><code>  &lt;div class="float-right"&gt;
     &lt;div class="float-left"&gt; &lt;input type="number" value="1" aria-label="Search" 
      class="form-control" style="width: 100px"&gt; &lt;/div&gt;
      &lt;a class="btn send-click btn-md my-0 p"  href="{% url 'cart:add_cart' product.id %}"&gt;Add to Cart&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  
  <p>urls.py</p>
  
  <pre><code>app_name='cart'
  
  urlpatterns = [
      path('add/&lt;int:product_id&gt;/', views.add_cart, name='add_cart'),
      path('', views.cart_detail, name='cart_detail'),
      path('remove/&lt;int:product_id&gt;/', views.cart_remove, name='cart_remove'),
      path('full_remove/&lt;int:product_id&gt;/', views.full_remove, name='full_remove'),
  ]
  </code></pre>