如何添加django_filters搜索表单作为modeladmin changelist页面本身的一部分。用户应该能够从各种模型属性中进行搜索,并且查询应该生成必要的搜索结果。使用django 1.6.5
答案 0 :(得分:0)
f = ModelFilter(request.GET, queryset=Model.objects.all())
paginator = Paginator(f.qs,100)
page = request.GET.get('page')
try:
modelobjects = paginator.page(page)
将值传递给上下文:
ctx = RequestContext(request, {
'filter':f,
'modelobjects': modelobjects,
})
在template.py中:
<div class="pagination">
<table border="1">
<tr>
<th>Sr.No.</th>
<th>Number </th>
</tr>
{% for line in modelobjects %}
<tr>
<td>{{ forloop.counter }}</td>
..........
在此处按照文档进行分页:https://docs.djangoproject.com/en/1.7/topics/pagination/#using-paginator-in-a-view这就是全部!