其他分享
首页 > 其他分享> > django 外键使用select html

django 外键使用select html

作者:互联网

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>

 

标签:all%,clickandback,代码,外键,endfor%,html,cab,select
来源: https://www.cnblogs.com/jingzaixin/p/11531456.html