1.HTML代码:
<td> <select id="depend_case" name="depend_case"> <option value="" {% if clickandback.depend_case_id == None %} selected="selected" {% endif %}> ---请选择 </option> {%for cab in clickandback_all%} <option value={{forloop.counter}} {% if cab.id == clickandback.depend_case_id%} selected="selected" {% endif %}> cab.test_case_title <!--[{{ cab.test_project }}]-[{{ cab.test_module }}]-[{{ cab.test_page }}]_{{cab.test_case_title }}--> </option> {%endfor%} </select> </td>
2.为外键时,value需要为外键的id,代码如下:
<td>
<select id="depend_case" name="depend_case">
<option value=""
{% if clickandback.depend_case_id == None %}
selected="selected"
{% endif %}>
---请选择
</option>
{%for cab in clickandback_all%}
<option
value={{cab.id}}
{% if cab.id == clickandback.depend_case_id%}
selected="selected"
{% endif %}>
[{{ cab.test_project }}]-[{{ cab.test_module }}]-[{{ cab.test_page }}]_{{cab.test_case_title }}]
</option>
{%endfor%}
</select>
</td>