Last active
April 1, 2016 22:37
-
-
Save craigderington/0a7ded018b8401bc42822b2eeaaff1cd to your computer and use it in GitHub Desktop.
Django Filters - PagedFilteredTableView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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