在django-filter页面启动时显示所有记录 [英] Display all record on django-filter page startup
问题描述
我遇到 django-filter上的空结果列表的反问题页面启动.我希望在启动时我的视图在用户可以应用过滤器之前显示所有记录.
I have the inverse problem of Empty result list on django-filter page startup. I would like that on startup my view display all records before user can apply filter.
我没有(在我的链接问题的答复中找到):
I don't have (found in the reply of my linked question) :
问题是,筛选器的默认视图是返回所有结果.
The problem is, the default view of a Filter is to return ALL the results.
这是我的观点:
class EntrepriseList(LoginRequiredMixin, SingleTableMixin, FilterView):
table_class = EntrepriseTable
model = Entreprise
template_name = 'stage/entreprise_list.html'
filterset_class = EntrepriseFilter
paginate_by = 30
还有我的过滤器:
class EntrepriseFilter(django_filters.FilterSet):
nom = django_filters.CharFilter(lookup_expr='icontains', label='nom')
ville = django_filters.CharFilter(lookup_expr='icontains', label='ville')
class Meta:
model = Entreprise
fields = ['nom', 'ville', 'secteur']
答案:
事实证明,就像在View类中将strict变量设置为False一样容易.
It turns out it's as easy as setting the strict variable to False in the View class.source
推荐答案
这是2.0版本中的已知错误.一种解决方法是设置 strict = False
.
This is a known bug in the 2.0 release. A workaround is to set strict=False
.
https://github.com/carltongibson/django-filter/issues/930#issuecomment-410177356
这篇关于在django-filter页面启动时显示所有记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!