Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

354
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda