これはテンプレートのフォームです。特定の項目に投票するためのループに 2 つのボタンを含む複数のフォームを作成していますが、見苦しいと思います。すべてのボタンに対して 1 つのフォームのみを使用することを避けるにはどうすればよいですか?
{% for bill_item in bill_items %}
<form action="{% url 'bills:change_quantity' bill_item.id %}" method="post">
{% csrf_token %}
<button name="up"></button>
<button name="down"></button>
</form>
{% endfor %}
ビューでの私のアクションです
def change_quantity(request, bill_item_id):
bill_item = BillItem.objects.get(pk=bill_item_id)
if 'up' in request.POST:
bill_item.increase()
elif 'down' in request.POST:
bill_item.decrease()
bill_item.save()
return HttpResponseRedirect('/bills/')