Exemple #1
0
def addItem(request):
#          submitted = False
#     if request.method == 'POST':
#         form = ProductForm(request.POST , request.FILES)# MUST ADD FOR FILE UPLOAD OTHERWISE ERROR
#         if form.is_valid():
#           form.save()
#           all_items = Product.objects.all
#           submitted = True
#           messages.success(request, ('Product item Has Been Added'))
#           return render(request, 'productList.html', {'all_items': all_items, "form": form, 'submitted': submitted})
#     else:
#         all_items = Product.objects.all
#         form = ProductForm()
#         return render(request, 'productList.html', {'all_items': all_items, "form": form, 'submitted': submitted})
     submitted = False
     if request.method == 'POST':
          MyaddItemForm = addItemForm(request.POST , request.FILES)

          if MyaddItemForm.is_valid():
               MyaddItemForm.save()
               all_items = Product.objects.all
               submitted = True
               messages.success(request, ('Item Has Been Added!'))
               return redirect('productShow_admin')
          
          else:
               all_items = Product.objects.all
               form = addItemForm()
               messages.success(request, ('Please fill out all the fields.!!'))
               return render(request,'addItem.html',{'all_items': all_items, "form": form, 'submitted': submitted})
     else:
          all_items = Product.objects.all
          form = addItemForm()
          return render(request,'addItem.html',{'all_items': all_items, "form": form, 'submitted': submitted})
Exemple #2
0
def Editsale(request,list_id):
     if request.method == 'POST':
          item = Product.objects.get(pk=list_id)
          MyeditItemForm = addItemForm(request.POST or None, instance=item)
          
          if MyeditItemForm.is_valid():
               MyeditItemForm.save()
               messages.success(request, ('The Sale Has Been Edited!'))
               return redirect('productShow_admin')

          else:
           messages.success(request, ('Something is wrong!'))
           item = Product.objects.get(pk=list_id)
           return render(request, 'Editsale.html', {'item': item})
     else:
           item = Product.objects.get(pk=list_id)
           return render(request, 'Editsale.html', {'item': item})