如何解决Python,Django:如何将选中的表行放入列表?
晚上好,
我希望有人知道我将表中所有选中的行放入多维列表(提交后)的问题的答案?
我知道我可以做这样的事情来获取 - 例如 - 所有检查过的 ID 到一个列表中:
模板:
<form action="" method="post">
{% csrf_token %}
<div class="table-wrapper">
<table class="table table-hover">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">id</th>
<th scope="col">country</th>
<th scope="col">continent</th>
<th scope="col">...</th>
</tr>
</thead>
<tbody>
{% for item in data %}
<tr>
<td>
<input type="checkbox" name="list_gap" value="{{ item.id }}">
</td>
<td>{{ item.id}}</td>
<td>{{ item.country }}</td>
<td>{{ item.continent}}</td>
<td>...</td>
views.py
if request.method == 'POST':
checked_data = request.POST.getlist('list_gap')
但正如前面提到的,这只会让我得到一个已检查 ID 的列表!有没有办法将行的所有数据放入多维列表中,例如..?
list_checked = [
[1,'country','continent','...'],[2,[3,...
]
感谢您的帮助,祝您晚安!
解决方法
我建议创建一个查询集来从数据库中提取实例。
<a routerLink="/route1" routerLinkActive #route1RLA="routerLinkActive" [active]="route1RLA.isActive">Route 1</a>
<a routerLink="/route2" routerLinkActive #route2RLA="routerLinkActive" [active]="route2RLA.isActive">Route 2</a>
<a routerLink="/route3" routerLinkActive #route3RLA="routerLinkActive" [active]="route3RLA.isActive">Route 3</a>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。