Skip to content

Instantly share code, notes, and snippets.

@craigderington
Last active April 1, 2016 22:37
Show Gist options
  • Save craigderington/0a7ded018b8401bc42822b2eeaaff1cd to your computer and use it in GitHub Desktop.
Save craigderington/0a7ded018b8401bc42822b2eeaaff1cd to your computer and use it in GitHub Desktop.
Django Filters - PagedFilteredTableView
from django_tables2 import SingleTableView
from django_tables2.config import RequestConfig
class PagedFilteredTableView(SingleTableView):
filter_class = None
formhelper_class = None
context_filter_name = 'filter'
def get_queryset(self, **kwargs):
qs = super(PagedFilteredTableView, self).get_queryset()
self.filter = self.filter_class(self.request.GET, queryset=qs)
self.filter.form.helper = self.formhelper_class()
return self.filter.qs
def get_context_data(self, **kwargs):
context = super(PagedFilteredTableView, self).get_context_data()
context[self.context_filter_name] = self.filter
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment