Python django-tables2-simplefilter工作示例

Python django-tables2-simplefilter工作示例,python,django,filtering,django-tables2,Python,Django,Filtering,Django Tables2,我正在测试django-tables2-simplefilter。 我需要更好地了解内部工作原理。 在文档中,关于定义过滤器: “将筛选选项添加到SingleTableView。在表中定义筛选列表 子类(不在Table.Meta中)。可能不安全。“ 我已经有了我的工作表,其中包含字段和元,以便对e select列进行排序 class CouponTable(tables.Table): coupon = tables.Column(verbose_name="Coupo

我正在测试django-tables2-simplefilter。 我需要更好地了解内部工作原理。 在文档中,关于定义过滤器:

“将筛选选项添加到SingleTableView。在表中定义筛选列表 子类(不在Table.Meta中)。可能不安全。“

我已经有了我的工作表,其中包含字段和元,以便对e select列进行排序

    class CouponTable(tables.Table):
         coupon = tables.Column(verbose_name="Coupon")
         description = tables.Column(accessor="coupon.description", verbose_name="Descrizione")
         activationDate = tables.DateColumn(verbose_name="Data di attivazione")
         useDate = tables.DateColumn(verbose_name="Data di utilizzo")
         sel =tables.CheckBoxColumn(accessor="pk", orderable=False )

         class Meta:
              model = yieldCoupons
              sequence= ("sel", "coupon", "description", "activationDate", "useDate")
              fields = ("sel", "coupon", "description", "activationDate", "useDate")
第一个问题是: 1.我应该在哪里定义过滤器

看看django-tables2-simplefilter的代码,我看到了模板和css。 我想我应该在我的模板中包含该模板,以显示可用的过滤器

这是正确的吗

提前谢谢

class CouponTable(tables.Table):

     coupon = tables.Column(verbose_name="Coupon")
     description = tables.Column(accessor="coupon.description", verbose_name="Descrizione")
     activationDate = tables.DateColumn(verbose_name="Data di attivazione")
     useDate = tables.DateColumn(verbose_name="Data di utilizzo")
     sel =tables.CheckBoxColumn(accessor="pk", orderable=False )
     filters = your_filters
     class Meta:
          model = yieldCoupons
          sequence= ("sel", "coupon", "description", "activationDate", "useDate")
          fields = ("sel", "coupon", "description", "activationDate", "useDate")
编辑: 函数F可以作为

from django_tables2_simplefilter import F

还有一个问题:定义过滤器的F函数似乎不可用,但我知道我已经正确安装了django-tables2-simplefilter。我需要导入一些特定的东西吗?从django_tables2_simplefilter import FAgain:我从django_tables2_simplefilter/views.py的第42行得到一个TypeError(字符串索引必须是整数,而不是str)。那一行的代码表示field=f['field']无法理解@普拉文