【问题标题】:django-tables2-simplefilter working exampledjango-tables2-simplefilter 工作示例
【发布时间】:2014-01-15 17:28:47
【问题描述】:

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

" 向 SingleTableView 添加过滤选项。在表格中定义过滤器列表 子类(不在 Table.Meta 中)。可能不安全。”

我已经有了我的工作表,带有字段和元数据来订购 e 选择列

    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。 我想我应该在我的模板中包含该模板以显示可用的过滤器。

这是正确的吗?

提前致谢

【问题讨论】:

    标签: python django filtering django-tables2


    【解决方案1】:
    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 导入 F
    • 再次:我在第 42 行从 django_tables2_simplefilter/views.py 收到 TypeError(字符串索引必须是整数,而不是 str)。该行的代码说 field = f['field'] 无法理解。 @praveen
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多