为模型列表使用布尔HTML表单的最佳方法是什么? 可以说这是我的模型:
class Comparison(model):
id = models.AutoField(primary_key=True)
score = models.IntegerField(blank=True, null=True)
is_matching = models.NullBooleanField()
我的观点:
def display(request):
comparisons = Comparison.objects.all()
context = {
'comparisons': comparisons
}
return render(request, 'display_comparisons.html', context)
还有我的模板:
<table>
{% for comparison in comparisons %}
<tr>
<td>
Here is some True / False button that should update is_matching
</td>
</tr>
{% endfor %}
</table>
现在,理想情况下,如果单击“真”按钮或“假”按钮,我的比较模型将更新。最好的方法是什么?