我已经实现了带有分页功能的Django table2,每页2000页25条记录。 我正在尝试做两件事:
详细信息:
我已经安装了Django过滤器,但是在table2中使用它时遇到了麻烦,我在filter.py中显示了来自文档的代码,我已经实现了bootstrap css,但是我只想过滤器,最好具有自定义过滤器表单布局的功能。
我需要添加一列,其中包含指向函数的链接,简单的url-详细信息在这里不重要:# tables.py
import django_tables2 as tables
from .models import Sample
class SampleTable(tables.Table):
class Meta:
model = Sample
# views.py
def detailcontainer(request, container_id):
unassigned_samples2 = Sample.objects.all()
table = SampleTable(unassigned_samples2)
RequestConfig(request, paginate={'per_page': 25}).configure(table)
return render(request, 'container/detailcontainer.html',
{'table':table})
# filters.py
from django_filters.views import FilterView
from django_tables2.views import SingleTableMixin
class FilterSample(SingleTableMixin, FilterView):
table_class = SampleTable
model = Sample
filterset_class = SampleFilter
# template # this is what the docs say, but I can't get the 'if filter' section to work
{% load render_table from django_tables2 %}
{% render_table table %}
{% if filter %}
<form action="" method="get" class="form form-inline">
{% bootstrap_form filter.form layout='inline' %}
{% bootstrap_button 'filter' %}
</form>
{% endif %}
。那么如何向表中添加额外的列?
我对相关部分进行总结的代码
{{1}}