python - 在 print() 上返回空查询集
问题描述
谁能帮我找出为什么这不起作用。
def return_bulk_books(request):
book = request.POST.getlist('marked_delete')
books = Books.objects.filter(id__in = book)
print(books)
print(books)
返回一个空的查询集,而不是按要求打印书籍中的所有项目。
这是模型。
<form method="post" action="{% url 'return_bulk_books' %}">
{% csrf_token %}
{% for message in messages %}
<div class="container text-center text-success">{{ message }}</div>
<table class="layout container">
<thead>
<th>Book</th>
<th>Reg No</th>
<th>Date of issue</th>
<th><input type="checkbox" id="select-all"></th>
<th>Actions</th>
</thead>
{% for item in all_borrowed %}
<tr>
<td>{{ item.book_id.book_name }}</td>
<td>{{ item.book_id.reg_no}}</td>
<td>{{ item.issue_date }}</td>
<td>
<input type="checkbox" name="marked_delete" value="{{ item.pk }}">
</td>
<td name = 'pk'><a onclick="return confirm('This book will be returned to the library. Hit ok to confirm..')" href="{% url 'return_book' item.book_id.pk %}" >Return</a> </td>
</tr>
{% endfor %}
</table>
{% endfor %}
<div class="container text-right">
<button class="btn btn-dark" id="return_all" hidden="hidden" onclick="return confirm('The selected items will be returned to the library. Are you sure about this???')">Return Selected</button>
</div>
</form>
解决方案
推荐阅读
- r - 如何在 R 中修改绘图上的现有轴?
- asp.net - 在创建视图 MVC ASP.NET Core 2 时设置默认输入值 Datetime.Now?
- javascript - 如何在我的服务器上压缩上传的视频?
- android - 设备通过以太网连接时如何设置 DNS?
- jquery - jQuery 搞乱了 CSS
- java - 必须存在至少一个 JPA 元模型
- sparql - 用于返回满足某些条件的实体的 SPARQL 查询
- c# - MVC 核心基于角色的身份验证参数化
- android - 从 android studio 重新安装后,无法正确检测到应用程序安装时间
- mysql - 为通用字符选择表排序规则