django-tables2 - 如何将 LazyPaginator 与 RequestConfig 和 Table 类一起使用?
问题描述
我想可视化一个大的索引表——大到count(*)
对我的用例来说太慢了。这是我的views.py代码:
import django_tables2
from projectname.models import Growth
def dashboard(request):
class StatisticsTable(django_tables2.Table):
class Meta:
model = Growth
table = StatisticsTable(Growth.objects.all())
django_tables2.RequestConfig(
request
).configure(table)
return render(request, "plain_table.html", {'table': table,
'title': 'Growth dashboard',
'search': None})
我一直在寻找有关如何在django_tables2.paginators.LazyPaginator
此处使用的示例,到目前为止只发现我应该将它作为paginate=
in传递django_tables2.RequestConfig
,但是如果我在那里传递对类的引用,我仍然会得到一个常规的分页器。在这种情况下,这个类的正确用途是什么?
解决方案
RequestConfig(paginate={"paginator_class": LazyPaginator}).configure(table)
推荐阅读
- reporting-services - 缺少父和子报表参数框
- android - 我可以使用 WebView 进行 Auth0 登录吗?
- python - 如何在字符串中搜索包括 \n 通过 re.search
- ruby-on-rails - 如何防止用户只输入 /.../model/model_id: 在 url 中访问其他用户在 Ruby on Rails 中的记录?
- python - 为什么我不想立即将所有可迭代对象转换为具有定义长度的对象(例如列表)?
- imputation - 当您有多个变量对具有缺失值的列不重要时,如何估算?
- javascript - 仅显示二维数组中的第一个元素
- python - 编写通过函数传递单词时不断得到错误的输出
- r - R中是否有相当于vb.net的instr
- assembly - ARM / AArch64 上的 DIVQ 对应物(用双宽度除数缩小除法)?