如何在Django中为模型列表使用布尔型TRUE False形式?

时间:2019-01-09 00:22:42

标签: python django django-models django-forms

为模型列表使用布尔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>

现在,理想情况下,如果单击“真”按钮或“假”按钮,我的比较模型将更新。最好的方法是什么?

0 个答案:

没有答案