Django: How to edit value and store back in database : <p>I'm working on an attendance register. So I've got an HTMl checkbox form where user can tick if person is here. If they are then the views will pull out the number of lessons person has in database and subtract 1 from the value. How can I achieve this? This is done using Django.</p>

<p>views.py:</p>

<pre><code>def present(request):
    students = Student.objects.filter(squad='LearnToSwim1')
    completed = request.GET.get('pre')
    for stu in students:
        if request.POST.get('completed', '') == 'on':
            print("Present!")
        #I don't know what to do here to extract the lessons_left and subtract 1 from it.
        else:
            print("Not present")
</code></pre>

<p>models.py:</p>

<pre><code>class Student(models.Model):
    student_name = models.CharField(max_length=200)
    squad = models.CharField(max_length=30, choices=SQUAD, default='INSERT_SQUAD')
    lessons_left=models.IntegerField(default=0)

    def __str__(self):
        return self.student_name
</code></pre>

<p>presentform.html:</p>

<pre><code>&lt;form action="/present/" method="POST"&gt;
        {% csrf_token %} 
        &lt;p&gt;
            &lt;input type="checkbox" id="completed" name="completed" /&gt;  
            &lt;label for="completed"&gt;Present&lt;/label&gt;
        &lt;/p&gt;
            &lt;input class="waves-effect waves-light btn" type='submit'/&gt; 
    &lt;/form&gt;
</code></pre>
