Please I have the model and the view below but I want a situation in which any value entered in the quantity field would be saved as a negative number in my database.
views.py
def post(self, request):
receiveform = ReceiveForm(request.POST or None)
stockform = StockForm(request.POST or None)
if request.method == 'POST':
if receiveform.is_valid() and stockform.is_valid():
receiveform.save()
stockform.save()
messages.success(request,('Data save succefully'))
return redirect('dashboard')
else:
print(receiveform.errors)
receiveform = ReceiveForm(request.POST or None)
context = {
'receiveform':receiveform,
'stockform':stockform,
}
return render(request, 'storesapp/receives.html', context)
models.py
class Receives(models.Model):
date = models.DateField(default=now)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
quantity = models.IntegerField(default='0', blank=True, null=True)