'Trying to set a minimum value within a form based on the total amount in the inventory

Views.py ( Where I want to check)

def addInProcess(request):

if request.user.is_authenticated:
    form = inProcess_form()
    if request.method =="POST":
        calc = InProcessPowder.objects.create(
            date = request.POST.get('date'),
            tc_date = request.POST.get('tc_date'),
            tc_weight = request.POST.get('tc_weight'),
            tc_remarks = request.POST.get('tc_remarks'),
            tgl_date = request.POST.get('tgl_date'),
            tgl_weight = request.POST.get('tgl_weight'),
            tgl_remarks = request.POST.get('tgl_remarks'),
            checked_by = request.user,
            
        )
    
    context = {'form': form}
    return render(request, 'base/InProcess/InProcess_form.html', context)
else:
    return render (request, 'landing.html')

and in our Home view we call this as the total inventory amount

def home(request):
  if request.user.is_authenticated:
      totalCal_yld = calamansi.objects.all().aggregate(Sum('yld'))['yld__sum'] or 0.00

This gets the total yield of calamansi juice from the calamansi object I want to compare tc_weight with totalCal_yld

What I am trying to do is I want to minus tc_weight(processes calamansi) from totalCal_yld and equal a total which will represent the inventory of calamansi. Since calamansi is an ingredient in TC we are trying to make sure that it won't go negative or even not give them the option to do so.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source