I have a javascript variable called "counter", which I want to use to update a counter variable instantiated in models.py.
Here is a snapshot of models.py
class Player(BasePlayer):
#track the number of times the user has lost window focus
blur_quantity = models.IntegerField(initial=0)
Here is an example of pages.html
{% block content %}
<button name="blur_button" value=counter onclick="Warn()" class="btn btn-primary btn-large">Blur Button</button>
{% endblock %}
{% block scripts %}
<script>
var counter = 0;
// Tracks window blurs
$( document ).ready(function() {
function onchange (evt) {
counter++;
console.log(counter);
}
window.onblur = onchange;
});
function Warn() {
alert(counter);
}
</script>
{% endblock %}
Now, whenever the user clicks the button, the value of "counter" should be stored somewhere. How do I update the value of blur_quantity in models.py (e.g. my Django database) to reflect the value attached to the blur_button?