【发布时间】:2020-08-02 03:42:42
【问题描述】:
我正在从选中的复选框中获取值列表,现在我想用我的模型过滤列表并仅获取列表中值的过滤结果
views.py
def ResultTest(request):
var = request.POST.get('selectedTests')
var1 = BookTest.objects.filter(test=v)
return render(request, 'posts/result.html',{'var1':var1})
html file
<div class="col-md-12" style="overflow: auto;">
<input type="hidden" id="selectedTests" name="selectedTests">
<input type="hidden" name="test_type" value="pathology">
<table id="example" class="display" >
<thead>
<tr>
<th>Sr.No</th>
<th>Select</th>
<th>Test</th>
<th>MRP</th>
<th>CC Rate</th>
</tr>
</thead>
<tbody>
{% for booktest in contact_list %}
<tr>
<td>{{ booktest.number }}
<td><input type="checkbox" name="check_list[]" value="{{ booktest.test }}" class="chkbox"/> </td>
<td>{{ booktest.test }}</td>
<td>{{ booktest.mrp }} </td>
<td>{{ booktest.rate }}</td>
</tr>
{% endfor %}
</tbody>
</table>
我正在为 selectedTests 获取值列表,现在我希望值列表在模型中过滤并获取值的所有数据。
【问题讨论】:
-
selectedTests中究竟存储了什么值(什么格式)?我不确定在这里使用隐藏字段是否是个好主意,因为它很容易被操纵。 -
实际上它的复选框选中值存储在 selectedTests 中,因此用户选中多个复选框,因此我在 selectedTests 中获得选中复选框的值列表,现在我想根据存储在中的值列表对其进行过滤selectedTests
-
好的,值的格式是什么?是
"1,2,3,4",还是"1 2 3 4",还是别的什么?为什么不直接发送复选框的值? -
值在“1,2,3,4”中
标签: javascript python django django-models filter