简体   繁体   English

django-tables2复选框列名

[英]django-tables2 checkbox column name

I've created my table output with django-tables2, but I want a specific name in the table column for the check-boxes. 我用django-tables2创建了我的表输出,但我想在表格列中为复选框指定一个特定的名称。

How can I do that ? 我怎样才能做到这一点 ?

Here is my class for the table drawing, I've modified the sequence of the columns so that my check-box is the first one. 这是我的表绘图类,我修改了列的顺序,以便我的复选框是第一个。

class SimpleTable(tables.Table):
    amend = tables.CheckBoxColumn(verbose_name=('Amend'), accessor='pk')

    class Meta:
        model = SysimpReleaseTracker
        attrs = {"class": "paleblue"}
        listAttrs = list()
        listAttr = list()
        listAttrs = SysimpReleaseTracker._meta.fields

        listAttr.append('amend')
        for x in listAttrs:
            listAttr.append('%s' %x.name)
        sequence = listAttr

CheckBoxColumn has it's own unique rendering for the header and so it will not show the verbose_name unlike all the other columns. CheckBoxColumn有自己独特的标题呈现,因此它不会显示verbose_name与其他所有列不同。 You could subclass CheckBoxColumn to change it's behavior though. 你可以继承CheckBoxColumn来改变它的行为。

class CheckBoxColumnWithName(tables.CheckBoxColumn):
    @property
    def header(self):
        return self.verbose_name

class SimpleTable(tables.Table):  
    amend = CheckBoxColumnWithName(verbose_name="Amend", accessor="pk")

Alternatively, you could use a TemplateColumn . 或者,您可以使用TemplateColumn

class SimpleTable(tables.Table):  
    amend = TemplateColumn('<input type="checkbox" value="{{ record.pk }}" />', verbose_name="Amend")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM