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

296
Vistas
Django: How to save javascript auto-increment to django database?

I am incrementing a value from my database evey 3.5 sec using javascript, but the value that i am incremeting is coming dynamically from the database, now i want to save the newly incremented value to the database as the increment keeps going, i don't know how to achieve this using django and javascript.

When i refresh the page, the value resets to the default value that i have in my database and doesn't update the value with the new increments

<span id="generated">{{total_points}}</span>

<!-- This is the js doing the increment function -->
<script>
    var i = {{total_points}};
    function increment() {
    i++;
    document.getElementById('generated').innerHTML = `₦` + Number(i).toLocaleString('en') + `.00`;
    }
    setInterval('increment()', 3140);
</script>

how do i save the new increments to the database? Do i need to provide my models.py?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

The total points and the increment you can save in the javascript value until there is a submit of the form. Then send the result in the request to safe it to the database. If you refresh the page you indeed loose the increment. It might also be interesting for you to safe stuff in localstorage because if the user then refreshes the localstorage is still there, but then you must take localstorage if there is one, {% else ... you must take {{total_points}} to start with, but also with this: Updating stuff to the database requires you to build a form and do a request.

about 4 years ago · Santiago Gelvez Denunciar
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