Integrating django-filters with django-tables

I want to implement Django-filters along with Django-tables. Facing issues in writing the classes and rendering templates is also a bit complicated. Please help !!
And Mr Vitor, if possible pls write blogs on more interesting topics and the about the Django-packages and all Django-stuff. Your stuff is good and explanation is also very simple.


def searchtable(request):
queryset = TransBase.objects.select_related().all().order_by(’-id’)
f = TransBaseFilter(request.GET, queryset=queryset)
table = SalesTable(f.qs)
RequestConfig(request, paginate={“per_page”: 25, “page”: 1}).configure(table)
return render(request, ‘trans/trans_searchtable.html’, {‘table’: table, ‘filter’: f})

makesure you have the having TransBaseFilter and with SalesTable available in hand. (Filters and table names for demo purpose only).

html file

{{ filter.form }}

{% render_table table %}

hope this works. any doubt please ask.

`<form action="" method="get">
	{{ filter.form }}
    <input class="btn btn-primary btn-sm mt-1 mb-1" type="submit" />
{% render_table table %}`

I checked out the __iter__ method for the FilterSet and it basically accesses the property qs . So @huiming’s answer works for me. I adapted your code as follows:

queryset = Fitzroyfalls.objects.select_related().all()
f = FitzroyfallsFilter(request.GET, queryset=queryset)
table = FitsroyFallsTable(f.qs)
RequestConfig(request, paginate={"per_page": 25, "page": 1}).configure(table)
return render(request, 'query.html', {'table': table, 'filter': f})

I’m using:


Try this it will help you.

For More Details visit: Django Classes in Pune