来自另一个未详述“基于类的视图”示例的线程。
Check and clear filters with django-filter
以下代码的CBV如下所示:
def product_list(request):
f = ProductFilter(request.GET, queryset=Product.objects.all())
has_filter = any(field in request.GET for field in
set(f.get_fields()))
return render(request, 'my_app/template.html', {
'filter': f,
'has_filter': has_filter
})
我尝试了许多添加到CBV代码中的迭代:
from django_filters.views import FilterView
from django_tables2.views import SingleTableMixin
class FilteredPersonListView(SingleTableMixin, FilterView):
table_class = PersonTable
model = Person
template_name = 'template.html'
filterset_class = PersonFilter
但是一旦包含该表就无法呈现。
任何帮助都将不胜感激。
丹