def saveProduct(request): from website.models import Product if request.method == 'POST': f = forms.newEditStockForm(request.POST, request.FILES) if f.is_valid(): f.save() return HttpResponse('saved!') else: return HttpResponse(str(f.errors)) return HttpResponse('error!')
def editProduct(request): from website.models import Product if request.method == 'POST': idToEdit = int(request.POST['hiddenInput']) instance = Product.objects.get(pk=idToEdit) f = forms.newEditStockForm(request.POST, request.FILES, instance=instance) if f.is_valid(): f.save() return HttpResponse('saved!') else: return HttpResponse(str(f.errors)) return HttpResponse('error!')
def index(request): from website.models import Product, Order context = dict() context["orderTable"] = Order.objects.values() context["productTable"] = Product.objects.values() newEditTransactionsForm = forms.newEditTransactionsForm() context["newEditTransactionsForm"] = newEditTransactionsForm newEditStockForm = forms.newEditStockForm() context["newEditStockForm"] = newEditStockForm return render(request, 'storeManagement/management.html', context)