def inventory(request): if request.method == 'POST': #get the pending invoice for this user. # if one doesn't exist then create a new one user_invoice = Invoice.get_cart_invoice(request.user) if not user_invoice: response = HttpResponse() response.status_code = 303 response['location'] = 'login' return response inventoryItem = InventoryType.objects.get(product_name=request.POST['item']) itemCount = int(request.POST['quantity']) #add invoice items to the invoice with the drone for x in range(itemCount): inv_item = InvoiceItem(invoice=user_invoice, inventory_type=inventoryItem) inv_item.save() #update the inventory count inventoryItem.stock_count = inventoryItem.stock_count - itemCount inventoryItem.save() response = HttpResponse() response.status_code = 303 if request.POST['submit'] == 'add and go to checkout': response['location'] = 'checkout' else: response['location'] = 'inventory#body' return response inventory_items = InventoryType.objects.all() context = {'inventory_items': inventory_items} return render(request, 'app/inventory.html', context)