我是Django的新手,在使用数据库对象执行操作时遇到了一些麻烦,但我需要选中复选框
models.py
class Scooter (models.Model):
name = models.CharField(max_length=100, verbose_name='name')
price = models.IntegerField(max_length=10, verbose_name='price')
url = models.URLField(verbose_name='url')
views.py
class MainView(TemplateView):
template_name = 'mainApp/index.html'
def get(self, request):
scooters = Scooter.objects.all().order_by('price')
return (render(request, self.template_name, context={'scooters':scooters}))
我的html模板是:
<table class="table table-sm table-borderless table-hover table-responsive-lg">
<caption>Перечень товаров</caption>
<thead class="thead-dark">
<tr>
<th scope="col"></th>
<th scope="col">№</th>
<th scope="col">Name</th>
<th scope="col">Price</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<form action="" method="post">
{% for elem in scooters %}
<tr>
<th>
<input type="checkbox" id="{{ elem.num }}" name="scooter_select" value="/{{ elem.num }}">
<label for="scooter{{ elem.num }}"></label>
</th>
<th>
{{ forloop.counter }}
</th>
<th scope="row">
<a href="{{ elem.url }}">{{ elem.name }}</a>
</th>
<td>{{ elem.price }}</td>
<td>
<a href="{{ elem.id }}/update" class="badge badge-warning" role="button" aria-pressed="true">Edit</a>
</td>
<td>
<a href="{{ elem.id }}/delete" class="badge badge-danger" role="button" aria-pressed="true">Delete</a>
</td>
</tr>
{% endfor %}
</form>
</tbody>
</table>
所以我不明白,如何捕获复选框对象中的所选对象?