title: Django: How to reduce stock quantity when an order is made?
body: <p>My goal is to reduce stock quantity when an order is created.
  My stock item is a Tyre.
  The tyre has a model field for quantity.</p>
  <p>Here is my views.py</p>
  <pre><code>from django.shortcuts import render, redirect
  from .models import OrderItem
  from .forms import OrderCreateForm
  from cart.cart import Cart
  from stock.models import Tyre, Branch 
  from django.contrib.auth.decorators import login_required
  
  
  @login_required(login_url=&quot;/accounts/login/&quot;)
  def order_create(request):
      cart = Cart(request)
      if request.method == 'POST':
          form = OrderCreateForm(request.POST)
          if form.is_valid():
              order = form.save()
              for item in cart:
                  OrderItem.objects.create(
                      order=order,
                      tyre=item['tyre'],
                      price=item['price'],
                      quantity=item['quantity']
                  )
  
                  # reduce tyre stock quantity
                  order_item = OrderItem.objects.get(id=id)
                  tyre = Tyre.objects.get(id=id)
                  tyre.quantity = tyre.quantity - order_item.quantity
                  tyre.save()
             
  
              cart.clear()
  
              return redirect('orders:sale-orders')
          # return render(request, 'orders/sale_orders.html', {'order': order})
      else:
          form = OrderCreateForm()
      return render(request, 'orders/create_order.html', {'form': form})
  
  </code></pre>
  <p>When i run the code, I got this error:
  TypeError at /orders/create/
  Field 'id' expected a number but got .</p>
  <p>Here is my models.py for the orders app:</p>
  <pre><code>from django.db import models
  from shop.models import Product
  
  class Order(models.Model):
      customer_name = models.CharField(max_length=60)
      contact = models.CharField(max_length=12)
      created = models.DateTimeField(auto_now_add=True)
      updated = models.DateTimeField(auto_now=True)
  
      class Meta:
          ordering = ('-created', )
  
      def __str__(self):
          return 'Order {}'.format(self.id)
  
      def get_total_cost(self):
          return sum(item.get_cost() for item in self.items.all())
  
  
  class OrderItem(models.Model):
      order = models.ForeignKey(Order, related_name='items', on_delete=models.CASCADE)
      tyre = models.ForeignKey(Tyre, related_name='order_items', on_delete=models.CASCADE)
      price = models.DecimalField(max_digits=10, decimal_places=2)
      quantity = models.PositiveIntegerField(default=1)
  
      def __str__(self):
          return '{}'.format(self.id)
  
      def get_cost(self):
          return self.price * self.quantity
  </code></pre>
  <p>I appreciate any help</p>