所以我有一张表,列出了我模型中的所有记录。 但是现在我正在尝试创建一个Checkbox并将其删除(有点像Django管理员方式),我找不到这方面的文档,因为我确信有几种方法可以解决这个问题。 但是我想弄清楚这样做的正确方法,我应该通过视图吗?
如何在html和view中为多个删除实例创建单个删除按钮。我没有使用表单 我拒绝这方面,但没有得到正确的解决方案 Django: writing a view to delete an item with checkboxes Deleting multiple rows in Django frontend
list.html
{% for obj in object_list %}
<tbody>
<tr>
<td><input type="checkbox" name="data" value="{{obj.id}}" ></td>
<td><a href='#' data-toggle="collapse" value="{{obj.id}}">{{ obj.id }}</td>
<td><a href='#demo' data-toggle="collapse">{{ obj.Full_Name }}</a></td>
<td><a href="#demo" data-toggle="collapse">{{ obj.Agency_Name}}</a></td>
<td><a href="#demo" data-toggle="collapse">{{ obj.Date_of_Birth}}</a></td>
<td><a href="#demo" data-toggle="collapse">{{ obj.Agency_Code}}</a></td>
<td><a href="#demo" data-toggle="collapse"><span class="label label-primary">{{ obj.Agent_Status}}</span></a></td>
<td class="text-right">
<a href="{{ obj.get_absolute_url }}" class="btn btn-warning btn-circle" type="button"><i class="fa fa-list-alt" aria-hidden="true"></i></a>
<a href="{% url 'customer:Agent_Edit' obj.id %}" class="btn btn-info btn-circle" type="button"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
#<a href="{% url 'customer:Agent_Delete' obj.id %}" class="btn btn-danger btn-circle" type="button"><i class="fa fa-trash" aria-hidden="true"></i></a>
#Remove this button and create single button for multiple delete
</td>
</tr>
</tbody>
{% endfor %}
view.py
def Agent_List(request, id=None): #list items
queryset = Agent.objects.order_by('id')
#queryset = Agent.objects.all()
query = request.GET.get('q')
if query:
queryset=queryset.filter(
Q(Aadhaar_Number__icontains=query) |
Q(PAN_Number__icontains=query) |
Q(Account_Number__icontains=query)
).distinct()
context = {
"object_list": queryset,
"Full_Name ": "Agent_List",
}
return render(request, "customer/Agent_List.html", context)
def Agent_Delete(request, id=None):
instance = get_object_or_404(Agent, id=id)
instance.delete()
messages.success(request, "Successfully deleted")
return redirect("customer:Agent_List")
在def Agent_Delete(request,id = None)中删除单个id。但如何删除所选的多个id。请提前告诉你。