代码之家  ›  专栏  ›  技术社区  ›  d33tah

如何将LazyPaginator与RequestConfig和Table类一起使用?

  •  0
  • d33tah  · 技术社区  · 6 年前

    我想想象一个大的,索引表-足够大的 count(*)

    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= django_tables2.RequestConfig ,但如果我传递对那里的类的引用,我仍然会得到一个常规分页符。在这种情况下,这个类的正确用法是什么?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Jieter    6 年前
    RequestConfig(paginate={"paginator_class": LazyPaginator}).configure(table)