Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use LazyPaginator together with RequestConfig and Table classes? #631

Closed
d33tah opened this issue Nov 8, 2018 · 3 comments
Closed

Comments

@d33tah
Copy link

d33tah commented Nov 8, 2018

This is a copy of this SO question: https://stackoverflow.com/q/53208617/1091116

I want to visualize a big, indexed table - big enough for count(*) to be too slow for my use case. Here's my views.py code:

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})

I was looking for examples on how to use django_tables2.paginators.LazyPaginator here and so far only found that I should pass it as a paginate= in django_tables2.RequestConfig, but I still get a regular paginator if I pass a reference to the class there. What's the proper use of this class in this context?

@jieter jieter closed this as completed in af25b25 Nov 11, 2018
@jieter
Copy link
Owner

jieter commented Nov 11, 2018

I've added an example to the RequestConfig docstring in af25b25:

RequestConfig(paginate={"paginator_class": LazyPaginator}).configure(table)

@d33tah
Copy link
Author

d33tah commented Nov 11, 2018

@jieter thanks! That greatly speeded up my application.

@jieter
Copy link
Owner

jieter commented Nov 11, 2018

Nice, we also enjoy it on multi-million record tables with possibly complex filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants