so, I made a Django code for booking car online services , renter can rent a car by pressing on a booking button that moves him to form page to enter his his information and chooses a starting and end date, so once he submits, the balance from his account to the owner's account will be transfers according to a specific mount that depends on the number days he picked ,, but the problem is -> the mount is not linked to the date fields so weather he chooses the date or not the mount will still be the same here's the view that handles the transaction...
def transfer_rent(renter, owner, amount,start_date,end_date):
if (renter.balance < amount):
return False
else:
renter.balance -= amount
owner.balance += amount
renter.save()
owner.save()
return True
def booking(request,pk):
form = bookingCreateForm(request.POST or None)
user = request.user
if form.is_valid():
rent = Rent.objects.get(pk=pk)
car_owner = rent.owner
if transfer_rent(user, car_owner, rent.per_day):
form.save()
messages.success(request,'Successfully Saved')
return redirect('/list_history')
else:
messages.error(request, 'Insufficient balance')
return redirect('/list_history')
context = {
"form": form,
"title": "Enter Your Credintials",
}
return render(request, "booking.html",context)