Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

295
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda