Hi,
I’m trying to build a swimming pool water test app as my first project but stumbled on a problem - I don’t know how to do mathematical operations between model fields. So, I have a function in models.py:
class PoolTest(models.Model):
location = models.CharField(max_length=50)
freecl = models.DecimalField(max_digits=5, decimal_places=2)
totalcl = models.DecimalField(max_digits=5, decimal_places=2)
Then I want to display it in .html file with:
Location: {{ pooltest.location }}<br>
Free Cl: {{ pooltest.freecl }}<br>
Total Cl: {{ pooltest.totalcl }}<br>
But I also need to show Combined Cl after Total Cl:, which is Combined Cl = Total Cl - Free Cl
How can I get it done, please?
Updated: There is my views.py
from django.shortcuts import render
from pooltest.models import PoolTest
def pooltest(request):
all_pooltests = PoolTest.objects.all()
return render(request, 'pooltest/home.html', {'all_pooltests':all_pooltests})