这是我的代码。
{% extends 'app.html' %}
{% block body %}
<div>
<div class="alert alert-info">Transaction / Returning</div>
<table id="table" class="table table-stripped">
<thead class="alert-success">
<tr>
<th>Student Name</th>
<th>Book Title</th>
<th>Book Author</th>
<th>Status</th>
<th>Date Returned</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for borrow in borrows %}
<tr>
<td>{{ borrow.student.all.0.firstname }} {{ borrow.student.all.0.lastname }}</td>
<td>{{ borrow.book.all.0.title }}</td>
<td>{{ borrow.book.all.0.author }}</td>
<td>{{ borrow.status }}</td>
<td>{{ borrow.date | date }}</td>
<td>
{% if borrow.status == "Returned" %}
<button disabled="disabled" class="btn btn-primary" type="button" href="#">
<span class="glyphicon glyphicon-check"></span> Returned
</button>
{% else %}
<form method="POST" action="">
{% csrf_token %}
<input type="hidden" name="borrow_id" value="{{ borrow.id }}"/>
<button class="btn btn-danger">
<span class="glyphicon glyphicon-unchecked"></span> Return
</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
是的,我想让所有的表格保持不变,但在 状态、返回日期、行动 应该被清除。在我的项目中看起来很脏,所以帮我解决这个问题。
您必须删除数据库中的数据才能清除这些条目。
要做到这一点,您可在您的 视图.py 文件,它将从你的数据库中删除一个特定的条目,使一切保持不变。
要访问该功能,请在您的html文件中添加一个按钮。
就这样了。
希望对你有所帮助!