我有一个表格模板,我想扩展它并添加一个单选按钮。我该怎么做?扩展Django表格模板
这是我的表模板:
<table class="table table-striped">
<thead>
<tr>
{% for heading in headings %}
<th class="col-head-{{ fields|get_item:forloop.counter0 }}">{{ heading }}</th>
{% endfor %}
<th> </th> <!-- edit -->
<th> </th> <!-- delete -->
</tr>
</thead>
<tbody>
{% for item in objects %}
<tr class="row-clickable">
{% for field in fields %}
<td class="col-item-{{ field }}">
{% block cell %}
{{ item|get_item:field }}
{% endblock %}
</td>
{% endfor %}
<td class="col-icon col-icon-edit"><button type="button" class="btn btn-sm btn-default"><span class="glyphicon glyphicon-pencil"> </span></button></td>
<td class="col-icon col-icon-remove"><button type="button" class="btn btn-sm btn-default"><span class="glyphicon glyphicon-trash"> </span></button></td>
</tr>
{% empty %}
<tr>
<td colspan="{{ fields|length }}">Nothing yet to display.</td>
<td colspan="2"> </td>
</tr>
{% endfor %}
</tbody>
</table>
,这是我的扩展表:
{% extends "frontend/table.html" %}
{% load frontend_extras %}
{% block cell %}
{% if field == "name" %}
{% if item.thumbnail %}
<a class="content-preview" href="{{ item.path }}" data- mimeType="{{ item.content_format }}" data-name="{{ item.name }}">
<img src="{{ item.thumbnail }}" class="img-thumbnail content- thumbnail">
</a>
<a class="content-name content-with-thumbnail content-preview" href="{{ item.path }}" data-mimeType="{{ item.content_format }}" data- name="{{ item.name }}">
{{ item.name }}
</a>
{% else %}
<a class="content-name content-no-thumbnail content-preview" href="{{ item.path }}" data-mimeType="{{ item.content_format }}" data-name="{{ item.name }}">
{{ item.name }}
</a>
{% endif %}
{% elif field == "content_size" %}
{{ item|get_item:field|filesizeformat }}
{% elif field == "content_duration" %}
{% if item|get_item:field %}
{{ item|get_item:field|duration }}
{% else %}
{% endif %}
{% else %}
{{ item|get_item:field }}
{% endif %}
{% endblock %}
我如何添加一个单选按钮来扩展表。
感谢您的帮助
的常用方法是使用你在你的模板调用一个形式。您可以在模型中使用BooleanField()创建单选按钮,并将其通过表单传递给模板。 – user1749431