传递复选框值以在django中查看

时间:2015-06-16 16:19:47

标签: django checkbox django-templates django-views

我有一个包含一些数据库数据的表

manager.Queue()

我希望为每个字段添加一个复选框,并传递已检查数据的ID以查看和进行组操作,而不是逐个删除项目。 我添加了这个复选框

<table id="id_list_table" class="table table-condensed">
<caption>Inputs list</caption>
    <thead>
      <tr>
        <th>#</th>
        <th id="input">Input</th>
      </tr>
    </thead>
    <tbody id="fbody">
    {%for input in InputsAll%}
        <tr>
            <td>{{ input.input }}</td>
            <td>
                <a class="btn btn-primary btn-xs" href="{% url 'edit' %}?input_num={{input.id}}" id="edit">edit</a>
                <a class="btn btn-danger btn-xs" href="{% url 'delete' %}?input_num={{input.id}}" id="remove">remove</a>
                <a class="btn btn-success btn-xs" href="{% url 'resolve' %}?input_num={{input.id}}"id="resolve">resolve</a>
                <input type="checkbox" name="inputs" id="option{{input.id}}" value={{input.id}} />
            </td>
        </tr>
    {%endfor%}
    </tbody>
</table>

我应该如何传递所有选中的值才能查看?这样做有用吗?

1 个答案:

答案 0 :(得分:3)

views.py

if request.method == 'POST':
        #gives list of id of inputs 
        list_of_input_ids=request.POST.getlist('inputs')

希望这能解决您的大部分问题。请查看此链接 Checkboxes for a list of items like in Django admin interface

相关问题