Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
How to automatically do calcuations using Javascript in django templates?

I have models:

class Payments(models.Model):
    paymentid = models.IntegerField(primary_key=True)
    bookingid = models.ForeignKey('Roombookings', models.DO_NOTHING, db_column='bookingid')
    paymenttype = models.CharField(max_length=255)
    paymentamount = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'payments'


class Roombookings(models.Model):
    bookingid = models.IntegerField(primary_key=True)
    customername = models.CharField(max_length=500, blank=True, null=True)
    customeraddress = models.CharField(max_length=550, blank=True, null=True)
    bookingfrom = models.DateField(blank=True, null=True)
    bookingto = models.DateField(blank=True, null=True)
    assignroomid = models.ForeignKey('Rooms', models.DO_NOTHING, db_column='assignroomid', blank=True, null=True)
    noofguests = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'roombookings'

class Rooms(models.Model):
    roomid = models.IntegerField(primary_key=True)
    roomnumber = models.IntegerField()
    roomprice = models.IntegerField()
    roomtype = models.CharField(max_length=255)
    roomcapacity = models.IntegerField()

    class Meta:
        managed = False
        db_table = 'rooms'

I want an automatic calculation of paymentamount when a bookingid is entered which works under the formula of 'bookingto-bookingfrom' date * roomprice from another table

My django views function:

def payments(request):
    if request.method == 'POST':
        form = PaymentsForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/payments done/')
    return render(request,'files/payments.html',{'form': PaymentsForm()}

In templates, I'm just using:

<form  action="" method="POST" >
    {% csrf_token %}
    {{form.as_p}}
   <input type = "submit" value ="Submit">

</form>

In the templates section, In the javascript part, I want to autofill the payment amount by doing some calculation.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!