Django-Filter:根据先前已过滤的结果进行过滤

时间:2020-01-03 10:34:53

标签: django python-3.x django-filter django-tables2

结合使用Django-Filter和Django-Tables2来显示一组已被过滤一次的分页对象。

class ResultFilter(django_filters.FilterSet):
    description = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = models.Legislation
        fields = "sector", "country", "act"

class ResultTable(django_tables2.Table):

    class Meta:
        template_name = "django_tables2/bootstrap4.html"
        model = models.Legislation
        exclude = "id",

class HomeView(django_tables2.SingleTableMixin, FilterView):
    template_name = "home.html"
    filterset_class = tables.ResultFilter
    table_class = tables.ResultTable
    paginate_by = 5

我正在努力弄清楚如何构建类似“过滤器开始”的东西,在该过滤器中可以重新过滤已经过滤的结果。

Concept of Filtering

我尝试了诸如将queryset.query原始sql字符串编码为url作为query_param的操作,因此,如果用户再次进行过滤-后端知道哪个查询之前已经执行过并且可以适应。

我真的不喜欢这种尝试。我敢肯定,有更好的方法可以做到这一点。

0 个答案:

没有答案